Class: RedditApi::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/reddit_api/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Query

Returns a new instance of Query.


7
8
9
10
11
12
13
# File 'lib/reddit_api/query.rb', line 7

def initialize(args = {})
  @count = args.fetch(:count)
  @endpoint = args.fetch(:endpoint, "")
  @offset_id = args.fetch(:offset, "")
  @records = args.fetch(:records, {})
  @resource_type = args.fetch(:resource, "")
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.


5
6
7
# File 'lib/reddit_api/query.rb', line 5

def count
  @count
end

#endpointObject (readonly)

Returns the value of attribute endpoint.


5
6
7
# File 'lib/reddit_api/query.rb', line 5

def endpoint
  @endpoint
end

#offset_idObject

Returns the value of attribute offset_id.


5
6
7
# File 'lib/reddit_api/query.rb', line 5

def offset_id
  @offset_id
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.


5
6
7
# File 'lib/reddit_api/query.rb', line 5

def resource_type
  @resource_type
end

Instance Method Details

#add_records(new_records) ⇒ Object


15
16
17
18
19
20
21
# File 'lib/reddit_api/query.rb', line 15

def add_records(new_records)
  if count > 1
    add_multiple_records(new_records)
  else
    add_single_record(new_records)
  end
end

#capture_countObject


27
28
29
# File 'lib/reddit_api/query.rb', line 27

def capture_count
  records.length
end

#captured_recordsObject


23
24
25
# File 'lib/reddit_api/query.rb', line 23

def captured_records
  records.values
end