Sha256: 651148af1d805819c7fb100fcc27d2fa4222a41e5f75e2b21ddbf6fa34273e15

Contents?: true

Size: 999 Bytes

Versions: 3

Compression:

Stored size: 999 Bytes

Contents

module Redd
  module Objects
    # A collection of reddit things.
    # @see https://www.reddit.com/dev/api#listings
    class Listing < Array
      # @!attribute [r] before
      # @return [String] The id of the object before the listing.
      attr_reader :before

      # @!attribute [r] after
      # @return [String] The id of the object after the listing.
      attr_reader :after

      # @param [Clients::Base] client The client to expand the comments with.
      # @param [{:before => String, :after => String,
      #   :children => Array<Hash>}] attributes The data to initialize the
      #   class with.
      # @todo Only call Clients::Base#object_from_body when item is being
      #   accessed.
      def initialize(client, attributes)
        @before = attributes[:before]
        @after = attributes[:after]
        attributes[:children].each do |child|
          self << client.object_from_body(child) || child
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redd-0.7.5 lib/redd/objects/listing.rb
redd-0.7.4 lib/redd/objects/listing.rb
redd-0.7.3 lib/redd/objects/listing.rb