Class: FederalRegister::ResultSet

Inherits:
Client
  • Object
show all
Includes:
Enumerable
Defined in:
lib/federal_register/result_set.rb

Direct Known Subclasses

PublicInspectionIssueResultSet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

get

Constructor Details

#initialize(attributes, result_class) ⇒ ResultSet

Returns a new instance of ResultSet.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/federal_register/result_set.rb', line 6

def initialize(attributes, result_class)
  @result_class = result_class
  @count = attributes['count']
  @total_pages = attributes['total_pages']
  @results = (attributes['results'] || []).map{|result| @result_class.new(result) }

  @description = attributes['description']

  @prev_url = attributes['previous_page_url']
  @next_url = attributes['next_page_url']
  @errors   = attributes['errors']
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



4
5
6
# File 'lib/federal_register/result_set.rb', line 4

def count
  @count
end

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/federal_register/result_set.rb', line 4

def description
  @description
end

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/federal_register/result_set.rb', line 4

def errors
  @errors
end

#resultsObject (readonly)

Returns the value of attribute results.



4
5
6
# File 'lib/federal_register/result_set.rb', line 4

def results
  @results
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



4
5
6
# File 'lib/federal_register/result_set.rb', line 4

def total_pages
  @total_pages
end

Class Method Details

.fetch(url, options = {}) ⇒ Object



27
28
29
30
31
# File 'lib/federal_register/result_set.rb', line 27

def self.fetch(url, options = {})
  result_class = options.delete(:result_class)
  response = get(url, options).parsed_response
  new(response, result_class)
end

Instance Method Details

#eachObject



33
34
35
# File 'lib/federal_register/result_set.rb', line 33

def each
  @results.each {|result| yield result }
end

#nextObject



19
20
21
# File 'lib/federal_register/result_set.rb', line 19

def next
  self.class.fetch(@next_url, :result_class => @result_class) if @next_url
end

#previousObject



23
24
25
# File 'lib/federal_register/result_set.rb', line 23

def previous
  self.class.fetch(@prev_url, :result_class => @result_class) if @prev_url
end