Class: GetYourRep::OpenStatesOffice
- Defined in:
- lib/get_your_rep/responses/open_states_office.rb
Overview
Parses office location information from Open States responses.
Instance Attribute Summary collapse
-
#city ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
-
#line_1 ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
-
#line_2 ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
-
#state ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
-
#zip ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
Instance Method Summary collapse
-
#address_to_ary ⇒ Object
Splits the address string into an array for hash assembly.
-
#build_hash ⇒ Object
Builds the hash to pass as constructor options for a new OfficeLocation.
-
#parse_address ⇒ Object
Assign elements of the address array to office attributes.
Methods inherited from Base
Constructor Details
This class inherits a constructor from GetYourRep::Base
Instance Attribute Details
#city ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
8 9 10 |
# File 'lib/get_your_rep/responses/open_states_office.rb', line 8 def city @city end |
#line_1 ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
8 9 10 |
# File 'lib/get_your_rep/responses/open_states_office.rb', line 8 def line_1 @line_1 end |
#line_2 ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
8 9 10 |
# File 'lib/get_your_rep/responses/open_states_office.rb', line 8 def line_2 @line_2 end |
#state ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
8 9 10 |
# File 'lib/get_your_rep/responses/open_states_office.rb', line 8 def state @state end |
#zip ⇒ Object
These accessor attributes are parsed from the :address attribute created at instantiation.
8 9 10 |
# File 'lib/get_your_rep/responses/open_states_office.rb', line 8 def zip @zip end |
Instance Method Details
#address_to_ary ⇒ Object
Splits the address string into an array for hash assembly.
22 23 24 25 26 27 |
# File 'lib/get_your_rep/responses/open_states_office.rb', line 22 def address_to_ary self.address = address.gsub("\n", ', ') self.address = address.split(', ') return if name.casecmp('capitol office') || name.casecmp('district office') address.unshift(name) end |
#build_hash ⇒ Object
Builds the hash to pass as constructor options for a new OfficeLocation.
30 31 32 33 34 35 36 37 38 |
# File 'lib/get_your_rep/responses/open_states_office.rb', line 30 def build_hash parse_address { type: type, line_1: line_1, line_2: line_2, city: city, state: state, zip: zip } end |
#parse_address ⇒ Object
Assign elements of the address array to office attributes.
11 12 13 14 15 16 17 18 19 |
# File 'lib/get_your_rep/responses/open_states_office.rb', line 11 def parse_address address_to_ary state_and_zip = address.pop.split(' ') self.state = state_and_zip.first self.zip = state_and_zip.last self.city = address.pop self.line_1 = address.shift self.line_2 = address[0] end |