Class: Twitter::TrendResults
- Inherits:
-
Object
- Object
- Twitter::TrendResults
- Includes:
- Memoizable, Creatable, Enumerable, Utils
- Defined in:
- lib/twitter/trend_results.rb
Overview
Represents a collection of trending topics
Instance Attribute Summary collapse
-
#attrs ⇒ Hash
(also: #to_h)
readonly
The raw attributes hash.
Instance Method Summary collapse
-
#as_of ⇒ Time
Returns the time when trends were retrieved.
-
#as_of? ⇒ Boolean
Returns true if as_of is available.
-
#initialize(attrs = {}) ⇒ Twitter::TrendResults
constructor
Initializes a new TrendResults object.
-
#location ⇒ Twitter::Place, NullObject
Returns the location for these trends.
-
#location? ⇒ Boolean
Returns true if location is available.
Methods included from Utils
Methods included from Enumerable
Methods included from Creatable
Constructor Details
#initialize(attrs = {}) ⇒ Twitter::TrendResults
Initializes a new TrendResults object
46 47 48 49 50 51 |
# File 'lib/twitter/trend_results.rb', line 46 def initialize(attrs = {}) @attrs = attrs @collection = @attrs.fetch(:trends, []).collect do |trend| Trend.new(trend) end end |
Instance Attribute Details
#attrs ⇒ Hash (readonly) Also known as: to_h
The raw attributes hash
21 22 23 |
# File 'lib/twitter/trend_results.rb', line 21 def attrs @attrs end |
Instance Method Details
#as_of ⇒ Time
Returns the time when trends were retrieved
59 60 61 |
# File 'lib/twitter/trend_results.rb', line 59 def as_of Time.parse(@attrs[:as_of]).utc unless @attrs[:as_of].nil? end |
#as_of? ⇒ Boolean
Returns true if as_of is available
70 71 72 |
# File 'lib/twitter/trend_results.rb', line 70 def as_of? !!@attrs[:as_of] end |
#location ⇒ Twitter::Place, NullObject
Returns the location for these trends
81 82 83 |
# File 'lib/twitter/trend_results.rb', line 81 def location location? ? Place.new(@attrs[:locations].first) : NullObject.new end |
#location? ⇒ Boolean
Returns true if location is available
92 93 94 |
# File 'lib/twitter/trend_results.rb', line 92 def location? !@attrs[:locations].nil? && !@attrs[:locations].first.nil? end |