Class: GetYourRep::OpenStatesOffice

Inherits:
Base
  • Object
show all
Defined in:
lib/get_your_rep/responses/open_states_office.rb

Overview

Parses office location information from Open States responses.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from GetYourRep::Base

Instance Attribute Details

#cityObject

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_1Object

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_2Object

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

#stateObject

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

#zipObject

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_aryObject

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_hashObject

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_addressObject

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