Class: Twitter::TrendResults

Inherits:
Object
  • Object
show all
Includes:
Memoizable, Creatable, Enumerable, Utils
Defined in:
lib/twitter/trend_results.rb

Overview

Represents a collection of trending topics

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

flat_pmap, pmap

Methods included from Enumerable

#each

Methods included from Creatable

#created?, #created_at

Constructor Details

#initialize(attrs = {}) ⇒ Twitter::TrendResults

Initializes a new TrendResults object

Examples:

Twitter::TrendResults.new(trends: [])

Parameters:

  • attrs (Hash) (defaults to: {})

    The attributes hash



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

#attrsHash (readonly) Also known as: to_h

The raw attributes hash

Examples:

results.attrs

Returns:

  • (Hash)


21
22
23
# File 'lib/twitter/trend_results.rb', line 21

def attrs
  @attrs
end

Instance Method Details

#as_ofTime

Returns the time when trends were retrieved

Examples:

results.as_of

Returns:

  • (Time)


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

Examples:

results.as_of?

Returns:

  • (Boolean)


70
71
72
# File 'lib/twitter/trend_results.rb', line 70

def as_of?
  !!@attrs[:as_of]
end

#locationTwitter::Place, NullObject

Returns the location for these trends

Examples:

results.location

Returns:



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

Examples:

results.location?

Returns:

  • (Boolean)


92
93
94
# File 'lib/twitter/trend_results.rb', line 92

def location?
  !@attrs[:locations].nil? && !@attrs[:locations].first.nil?
end