1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
require 'memoizable'
require 'twitter/creatable'
require 'twitter/enumerable'
require 'twitter/null_object'
require 'twitter/utils'
module Twitter
class TrendResults
include Twitter::Creatable
include Twitter::Enumerable
include Twitter::Utils
include Memoizable
# @return [Hash]
attr_reader :attrs
alias to_h attrs
alias to_hash to_h
# Initializes a new TrendResults object
#
# @param attrs [Hash]
# @return [Twitter::TrendResults]
def initialize(attrs = {})
@attrs = attrs
@collection = @attrs.fetch(:trends, []).collect do |trend|
Trend.new(trend)
end
end
# Time when the object was created on Twitter
#
# @return [Time]
def as_of
Time.parse(@attrs[:as_of]).utc unless @attrs[:as_of].nil?
end
memoize :as_of
def as_of?
!!@attrs[:as_of]
end
memoize :as_of?
# @return [Twitter::Place, NullObject]
def location
location? ? Place.new(@attrs[:locations].first) : NullObject.new
end
memoize :location
# @return [Boolean]
def location?
!@attrs[:locations].nil? && !@attrs[:locations].first.nil?
end
memoize :location?
end
end
|