Class: Tweet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, hashtags, twitter_client) ⇒ Tweet

Returns a new instance of Tweet.



4
5
6
7
8
# File 'lib/tweet.rb', line 4

def initialize(text, hashtags, twitter_client)
  @text = text
  @hashtags = hashtags
  @twitter_client = twitter_client
end

Instance Attribute Details

#hashtagsObject

Returns the value of attribute hashtags.



2
3
4
# File 'lib/tweet.rb', line 2

def hashtags
  @hashtags
end

Instance Method Details

#append(text) ⇒ Object



27
28
29
# File 'lib/tweet.rb', line 27

def append(text)
  @text << ' ' << text
end

#lengthObject



23
24
25
# File 'lib/tweet.rb', line 23

def length
  with_hashtags.length
end

#post!(image = '') ⇒ Object



10
11
12
13
14
15
16
17
# 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_hashtagsObject



19
20
21
# File 'lib/tweet.rb', line 19

def with_hashtags
  (@hashtags && @hashtags.size > 0) ? "#{@text}#{hashtags.reduce('') { |str, h| str << " ##{h}" }}" : @text
end