Class: Tweet
- Inherits:
-
Object
- Object
- Tweet
- Defined in:
- lib/tweet.rb
Instance Attribute Summary collapse
-
#hashtags ⇒ Object
Returns the value of attribute hashtags.
Instance Method Summary collapse
- #append(text) ⇒ Object
-
#initialize(text, hashtags, twitter_client) ⇒ Tweet
constructor
A new instance of Tweet.
- #length ⇒ Object
- #post!(image = '') ⇒ Object
- #with_hashtags ⇒ Object
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, , twitter_client) @text = text @hashtags = @twitter_client = twitter_client end |
Instance Attribute Details
#hashtags ⇒ Object
Returns the value of attribute hashtags.
2 3 4 |
# File 'lib/tweet.rb', line 2 def @hashtags end |
Instance Method Details
#append(text) ⇒ Object
27 28 29 |
# File 'lib/tweet.rb', line 27 def append(text) @text << ' ' << text end |
#length ⇒ Object
23 24 25 |
# File 'lib/tweet.rb', line 23 def length .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., File.new(image)) File.delete(image) else @twitter_client.update(self.) end end |
#with_hashtags ⇒ Object
19 20 21 |
# File 'lib/tweet.rb', line 19 def (@hashtags && @hashtags.size > 0) ? "#{@text}#{.reduce('') { |str, h| str << " ##{h}" }}" : @text end |