TweetValidator
tweet length check validator
Requirements
- ruby 2.0+
- activesupport, activemodel 4.0+
Installation
Add this line to your application's Gemfile:
gem 'tweet_validator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tweet_validator
Usage
class Tweet < ActiveRecord::Base
validates :message, tweet_length: true
end
Not Rails
include TweetValidator
manually
class Tweet < ActiveRecord::Base
include TweetValidator
validates :message, tweet_length: true
end
Specification
calculate the length excluding %<〜>
and %{〜}
Example
tweet.message = "a" * 140
tweet.valid?
# => true
tweet.message = "a" * 141
tweet.valid?
# => false
tweet.message = "a" * 140 + "%{screen_name}"
tweet.valid?
# => true
# url length is calculated as t.co
"https://github.com/sue445/tweet_validator".length
# => 41
tweet.message = "a" * 110 + "https://github.com/sue445/tweet_validator"
tweet.valid?
# => true
Configuration
TweetValidator.config.short_url_length = 22
TweetValidator.config.short_url_length_https = 23
If short_url_length
and short_url_length_https
is changed, please set new value.
see. https://dev.twitter.com/rest/reference/get/help/configuration
Changelog
0.0.2
- check
t.co
url length
0.0.1
- first release
Contributing
- Fork it ( https://github.com/sue445/tweet_validator/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request