Class: PYR::Resource

Inherits:
Object
  • Object
show all
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

Districts, OfficeLocations, Reps, States, Zctas

Defined Under Namespace

Classes: Districts, OfficeLocations, Reps, States, Zctas

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#controllerObject (readonly)

Read the ‘controller`



21
22
23
# File 'lib/pyr/resource.rb', line 21

def controller
  @controller
end

#idObject

Read the ‘id`



19
20
21
# File 'lib/pyr/resource.rb', line 19

def id
  @id
end

Instance Method Details

#to_sObject



32
33
34
# File 'lib/pyr/resource.rb', line 32

def to_s
  "#{controller}#{id}?#{params.map(&:to_s).join('&')}"
end