Class: PYR::Resource
- Inherits:
-
Object
- Object
- PYR::Resource
- Defined in:
- lib/pyr/resource.rb,
lib/pyr/resources/reps.rb,
lib/pyr/resources/zctas.rb,
lib/pyr/resources/states.rb,
lib/pyr/resources/districts.rb,
lib/pyr/resources/office_locations.rb
Overview
Resource and its subclasses accept attribute params and, in conjunction with instances of the Param class, convert them to a URI friendly string. When a block is passed to ‘PYR.call(name)`, it yields a Resource object, on which param setter methods can be called. The exact type of Resource that is yielded depends on the name that is passed to the method.
Example
PYR.call(:reps) do |r| # yielding an instance of PYR::Resource::Reps
r.address = 'Somewhere in the USA' # The `address` param is available
end
Direct Known Subclasses
Defined Under Namespace
Classes: Districts, OfficeLocations, Reps, States, Zctas
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Read the ‘controller`.
-
#id ⇒ Object
Read the ‘id`.
Instance Method Summary collapse
-
#initialize(controller, id) ⇒ Resource
constructor
A new instance of Resource.
- #to_s ⇒ Object
Constructor Details
#initialize(controller, id) ⇒ Resource
Returns a new instance of Resource.
23 24 25 26 |
# File 'lib/pyr/resource.rb', line 23 def initialize(controller, id) @controller = controller self.id = id end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Read the ‘controller`
21 22 23 |
# File 'lib/pyr/resource.rb', line 21 def controller @controller end |
#id ⇒ Object
Read the ‘id`
19 20 21 |
# File 'lib/pyr/resource.rb', line 19 def id @id end |
Instance Method Details
#to_s ⇒ Object
32 33 34 |
# File 'lib/pyr/resource.rb', line 32 def to_s "#{controller}#{id}?#{params.map(&:to_s).join('&')}" end |