Class: TweetSearch::Tweet
- Inherits:
-
Object
- Object
- TweetSearch::Tweet
- Defined in:
- lib/tweetsearch/tweet.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#media_urls ⇒ Object
readonly
Returns the value of attribute media_urls.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Tweet
constructor
A new instance of Tweet.
Constructor Details
#initialize(data) ⇒ Tweet
Returns a new instance of Tweet.
6 7 8 9 10 11 |
# File 'lib/tweetsearch/tweet.rb', line 6 def initialize(data) @id = data['id'] @created_at = DateTime.parse(data['created_at']) @text = data['text'] @media_urls = data.dig('entities', 'media')&.map { |media| media['media_url_https'] } end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/tweetsearch/tweet.rb', line 4 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/tweetsearch/tweet.rb', line 4 def id @id end |
#media_urls ⇒ Object (readonly)
Returns the value of attribute media_urls.
4 5 6 |
# File 'lib/tweetsearch/tweet.rb', line 4 def media_urls @media_urls end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
4 5 6 |
# File 'lib/tweetsearch/tweet.rb', line 4 def text @text end |
Class Method Details
.find_by(tags:, **options) ⇒ Object
13 14 15 16 17 |
# File 'lib/tweetsearch/tweet.rb', line 13 def self.find_by(tags:, **) tweets = TwitterClient.search_tweets() tweets.select! { |data| data.dig('entities', 'media') } if [:media_only] tweets.map { |data| new(data) } end |