class Bluebird::Tweet
Attributes
media[R]
original_status[R]
partials[R]
Public Class Methods
new(status, opts = {})
click to toggle source
# File lib/bluebird/tweet.rb, line 8 def initialize(status, opts = {}) @original_status = status @partials = [] extract_partials(status) @media = opts[:media] if opts.has_key?(:media) end
Public Instance Methods
add_partial(content, partial_type)
click to toggle source
# File lib/bluebird/tweet.rb, line 43 def add_partial(content, partial_type) if eligible_content?(content) partial = Partial.new(content, partial_type) if (last = partials.last) last.next_partial = partial partial.prev_partial = last end partials << partial end end
cashtag_partials()
click to toggle source
# File lib/bluebird/tweet.rb, line 39 def cashtag_partials partials.select { |partial| partial.cashtag? } end
hashtag_partials()
click to toggle source
# File lib/bluebird/tweet.rb, line 35 def hashtag_partials partials.select { |partial| partial.hashtag? } end
length()
click to toggle source
# File lib/bluebird/tweet.rb, line 19 def length total_partial_length + media_length end
mention_partials()
click to toggle source
# File lib/bluebird/tweet.rb, line 31 def mention_partials partials.select { |partial| partial.mention? } end
status()
click to toggle source
# File lib/bluebird/tweet.rb, line 15 def status partials.map { |partial| partial.content }.join end
text_partials()
click to toggle source
# File lib/bluebird/tweet.rb, line 23 def text_partials partials.select { |partial| partial.text? } end
url_partials()
click to toggle source
# File lib/bluebird/tweet.rb, line 27 def url_partials partials.select { |partial| partial.url? } end
Private Instance Methods
eligible_content?(content)
click to toggle source
# File lib/bluebird/tweet.rb, line 108 def eligible_content?(content) content.char_length > 0 end
ending_partial?(index, length)
click to toggle source
# File lib/bluebird/tweet.rb, line 104 def ending_partial?(index, length) index <= length end
entity_type(entity)
click to toggle source
# File lib/bluebird/tweet.rb, line 92 def entity_type(entity) if entity.has_key?(:screen_name) entity[:list_slug].empty? ? :mention : :list elsif entity.has_key?(:hashtag) :hashtag elsif entity.has_key?(:url) :url elsif entity.has_key?(:cashtag) :cashtag end end
extract_partials(status)
click to toggle source
# File lib/bluebird/tweet.rb, line 72 def extract_partials(status) entities = extract_entities_with_indices(status, extract_url_without_protocol: true) length = status.char_length index = 0 entities.each do |entity| first = entity[:indices].first last = entity[:indices].last add_partial(status[index, first - index], :text) add_partial(status[first, last - first], entity_type(entity)) index = last end if ending_partial?(index, length) add_partial(status[index, length - index], :text) end end
media_length()
click to toggle source
# File lib/bluebird/tweet.rb, line 68 def media_length media ? Config.characters_reserved_per_media : 0 end
total_partial_length()
click to toggle source
# File lib/bluebird/tweet.rb, line 58 def total_partial_length total = 0 partials.each do |partial| total += partial.length end total end