TweetValidator

tweet length check validator

Gem Version Build Status Dependency Status Code Climate Coverage Status

Requirements

ruby 2.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 + "http://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

full changelog

0.0.2

full changelog

0.0.1

  • first release

Contributing

  1. Fork it ( https://github.com/sue445/tweet_validator/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request