Bluebird Gem Version

Bluebird modifies your tweets, mostly to fit 140 characters.
It uses "strategies". Every strategy makes its own modifications to the tweets.
It does not ensure that tweet will fit 140 characters. (More strategies will be added to ensure it.)

Installation

Add this line to your application's Gemfile:

gem 'bluebird'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bluebird

Configuration

You do not need any configuration to start using bluebird but it is intended for a quick start. characters_reserved_per_media, short_url_length_https and short_url_length can change any time, it is your duty to fetch these values from twitter API and change bluebird configuration. For more information visit twitter docs.

These are the default values:

Bluebird.configure do |config|
  config.strategies                    = [:strip, :squeeze, :truncate_text]
  config.max_length                    = 140
  config.characters_reserved_per_media = 23
  config.short_url_length_https        = 23
  config.short_url_length              = 22

  config.truncate_text.omission        = '...'
end

If you want to change defaults for Rails, create a file in initializers folder and copy the code above.

By default bluebird runs three strategies in these order; strip, squeeze and truncate_text. For detailed information about each strategy, visit Strategies.

Usage

Bluebird.modify('The bluebirds are a group of medium-sized, mostly insectivorous or omnivorous birds in the genus Sialia of the thrush family (Turdidae). #bluebird #animals')
# => 'The bluebirds are a group of medium-sized, mostly insectivorous or omnivorous birds in the genus Sialia of the thrush ... #bluebird #animals'

If uploading media:

Bluebird.modify('The bluebirds are a group of medium-sized, mostly insectivorous or omnivorous birds in the genus Sialia of the thrush family (Turdidae). #bluebird #animals', media: true)
# => 'The bluebirds are a group of medium-sized, mostly insectivorous or omnivorous birds in the genu... #bluebird #animals'

License

Bluebird is released under the MIT License.