Sha256: 589500183428f66f8ca6ec54a2f56b22bcfcdba6e470077a29b8738ca3d67474

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true
require_relative './base'

module GetYourRep
  # Parses office location information from Open States responses.
  class OpenStatesOffice < Base
    # These accessor attributes are parsed from the :address attribute created at instantiation.
    attr_accessor :line_1, :line_2, :city, :state, :zip

    # Assign elements of the address array to office attributes.
    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

    # Splits the address string into an array for hash assembly.
    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

    # Builds the hash to pass as constructor options for a new OfficeLocation.
    def build_hash
      parse_address
      { type:   type,
        line_1: line_1,
        line_2: line_2,
        city:   city,
        state:  state,
        zip:    zip,
        phone:  phone }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
get_your_rep-1.2.0 lib/get_your_rep/responses/open_states_office.rb
get_your_rep-1.1.1 lib/get_your_rep/responses/open_states_office.rb
get_your_rep-1.1.0 lib/get_your_rep/responses/open_states_office.rb