0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
tweet length check validator
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

TweetValidator

tweet length check validator

Gem Version Build Status Code Climate Coverage Status

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

full changelog

0.0.2

full changelog

  • check t.co url length

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