Class: Tweet
- Inherits:
-
Object
- Object
- Tweet
- Defined in:
- lib/tweet.rb
Instance Attribute Summary collapse
-
#hashtag ⇒ Object
readonly
Returns the value of attribute hashtag.
Instance Method Summary collapse
- #append(text) ⇒ Object
-
#initialize(text, hashtag, twitter_client) ⇒ Tweet
constructor
A new instance of Tweet.
- #length ⇒ Object
- #post!(image = '') ⇒ Object
- #with_hashtag ⇒ Object
Constructor Details
#initialize(text, hashtag, twitter_client) ⇒ Tweet
Returns a new instance of Tweet.
4 5 6 7 8 |
# File 'lib/tweet.rb', line 4 def initialize(text, hashtag, twitter_client) @text = text @hashtag = hashtag @twitter_client = twitter_client end |
Instance Attribute Details
#hashtag ⇒ Object (readonly)
Returns the value of attribute hashtag.
2 3 4 |
# File 'lib/tweet.rb', line 2 def hashtag @hashtag 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 with_hashtag.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_hashtag, File.new(image)) File.delete(image) else @twitter_client.update(self.with_hashtag) end end |
#with_hashtag ⇒ Object
19 20 21 |
# File 'lib/tweet.rb', line 19 def with_hashtag (@hashtag && @hashtag.length > 0) ? "#{@text} ##{@hashtag}" : @text end |