class Tweet

Attributes

hashtags[RW]

Public Class Methods

new(text, hashtags, twitter_client) click to toggle source
# File lib/tweet.rb, line 4
def initialize(text, hashtags, twitter_client)
  @text = text
  @hashtags = hashtags
  @twitter_client = twitter_client
end

Public Instance Methods

append(text) click to toggle source
# File lib/tweet.rb, line 27
def append(text)
  @text << ' ' << text
end
length() click to toggle source
# File lib/tweet.rb, line 23
def length
  with_hashtags.length
end
post!(image = '') click to toggle source
# File lib/tweet.rb, line 10
def post!(image = '')
  if image.length > 0 && File.exists?(image)
    @twitter_client.update_with_media(self.with_hashtags, File.new(image))
    File.delete(image)
  else
    @twitter_client.update(self.with_hashtags)
  end
end
with_hashtags() click to toggle source
# File lib/tweet.rb, line 19
def with_hashtags
  (@hashtags && @hashtags.size > 0) ? "#{@text}#{hashtags.reduce('') { |str, h| str << " ##{h}" }}" : @text
end