Sha256: 2364ea09ff634297f24cea72844e4b31199dd2f91e969a8da4de56b20ba7d8f4
Contents?: true
Size: 757 Bytes
Versions: 15
Compression:
Stored size: 757 Bytes
Contents
module ConsadoleAggregator class Helper PLACE_HOLDER = '@' PLACE_HOLD_MATCHER = Regexp.compile("#{PLACE_HOLDER}{20}") 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 private def self.omit text, over_size truncated = text.slice(0...-over_size) truncated[-3..-1] = '...' truncated end end end
Version data entries
15 entries across 15 versions & 1 rubygems