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.



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

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.



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

def count
  @count
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

#offset_idObject

Returns the value of attribute offset_id.



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

def offset_id
  @offset_id
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



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

def resource_type
  @resource_type
end

Instance Method Details

#add_records(new_records) ⇒ Object



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

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

#capture_countObject



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

def capture_count
  records.length
end

#captured_recordsObject



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

def captured_records
  records.values
end