Sha256: 8e1a6f97cf47e5856a79aa54d8ac0f3a725d2feaa61880762a5efdf482ed4389

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

require 'twitter/creatable'
require 'twitter/enumerable'
require 'memoizable'
require 'twitter/null_object'

module Twitter
  class TrendResults
    include Twitter::Creatable
    include Twitter::Enumerable
    include Memoizable
    attr_reader :attrs
    alias_method :to_h, :attrs
    alias_method :to_hash, :attrs
    alias_method :to_hsh, :attrs

    class << self
      # Construct a new TrendResults object from a response hash
      #
      # @param response [Hash]
      # @return [Twitter::Base]
      def from_response(response = {})
        new(response[:body].first)
      end
    end

    # Initializes a new TrendResults object
    #
    # @param attrs [Hash]
    # @return [Twitter::TrendResults]
    def initialize(attrs = {})
      @attrs = attrs
      @collection = Array(@attrs[:trends]).map 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]) if @attrs[:as_of]
    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

5 entries across 5 versions & 1 rubygems

Version Path
twitter-5.4.1 lib/twitter/trend_results.rb
twitter-5.4.0 lib/twitter/trend_results.rb
twitter-5.3.1 lib/twitter/trend_results.rb
twitter-5.3.0 lib/twitter/trend_results.rb
twitter-5.2.0 lib/twitter/trend_results.rb