Class: ConsadoleAggregator::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/consadole_aggregator/helper.rb

Constant Summary collapse

PLACE_HOLDER =
'@'
PLACE_HOLD_MATCHER =
Regexp.compile("#{PLACE_HOLDER}{20}")

Class Method Summary collapse

Class Method Details

.truncate_for_twitter(text, opt = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/consadole_aggregator/helper.rb', line 6

def self.truncate_for_twitter text, opt={}
  url_place_holder = opt[:url] && PLACE_HOLDER*20 # twitter compress url to t.co as length 20 characters.
  base = "#{text} #{url_place_holder} #{opt[:hashtag]}".squeeze(' ').rstrip
  if base.size > 140
    over_size = base.size - 140
    self.truncate_for_twitter(omit(text, over_size), opt)
  else
    base.gsub(PLACE_HOLD_MATCHER) { opt[:url] } # revert place holder to url
  end
end