Sha256: 5b06c2b6deb4785ccf3d419d8d4050fc67ab650c34e41c216867d8ac103d6ceb

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

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_method :to_h, :attrs
    alias_method :to_hash, :to_h
    deprecate_alias :to_hsh, :to_hash

    # 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]) 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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twitter-5.15.0 lib/twitter/trend_results.rb
twitter-5.14.0 lib/twitter/trend_results.rb
twitter-5.13.0 lib/twitter/trend_results.rb
twitter-5.12.0 lib/twitter/trend_results.rb