Class: Redd::Models::Listing

Inherits:
Model
  • Object
show all
Includes:
Enumerable
Defined in:
lib/redd/models/listing.rb

Overview

A backward-expading listing of items.

See Also:

  • Stream

Instance Attribute Summary collapse

Attributes inherited from Model

#client

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, attributes = {}) ⇒ Listing

Create a fully initialized listing.

Parameters:

  • client (APIClient)

    the api client

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

    the attribute hash


22
23
24
25
# File 'lib/redd/models/listing.rb', line 22

def initialize(client, attributes = {})
  super
  fully_loaded!
end

Instance Attribute Details

#afterString (readonly)

Returns the fullname of the item that the next listing will start from.

Returns:

  • (String)

    the fullname of the item that the next listing will start from


45
# File 'lib/redd/models/listing.rb', line 45

property :after, :nil

#beforeString (readonly)

Returns the fullname of the item before this listing.

Returns:

  • (String)

    the fullname of the item before this listing


41
# File 'lib/redd/models/listing.rb', line 41

property :before, :nil

#childrenArray<Model> (readonly)

Returns the listing's children.

Returns:

  • (Array<Model>)

    the listing's children


49
# File 'lib/redd/models/listing.rb', line 49

property :children, :required, with: ->(a) { a.map { |m| client.unmarshal(m) } }

Class Method Details

.empty(client) ⇒ Listing

Create an empty listing with a client.

Parameters:

  • client (APIClient)

    the client to create the listing with

Returns:


15
16
17
# File 'lib/redd/models/listing.rb', line 15

def self.empty(client)
  Listing.new(client, children: [])
end

Instance Method Details

#to_aArray<Comment, Submission, PrivateMessage> Also known as: to_ary

Returns an array representation of self.

Returns:


28
29
30
# File 'lib/redd/models/listing.rb', line 28

def to_a
  read_attribute(:children)
end