Class: FederalRegister::FacetResultSet

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

get

Constructor Details

#initialize(attributes, result_class, options = {}) ⇒ FacetResultSet

Returns a new instance of FacetResultSet.



6
7
8
9
10
11
12
13
14
# File 'lib/federal_register/facet_result_set.rb', line 6

def initialize(attributes, result_class, options={})
  @result_class = result_class
  @conditions = options[:query] || {}

  @results = (attributes || {}).map do |slug, attributes|
    attributes["slug"] = slug
    @result_class.new(attributes, options.merge(:result_set => self) )
  end
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



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

def conditions
  @conditions
end

#resultsObject (readonly)

Returns the value of attribute results.



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

def results
  @results
end

Class Method Details

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



16
17
18
19
20
# File 'lib/federal_register/facet_result_set.rb', line 16

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

Instance Method Details

#eachObject



22
23
24
# File 'lib/federal_register/facet_result_set.rb', line 22

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