Sha256: b5320b149e1361488c854e50556f671a1d3410eb3cf9bc8c2e73a5767425e5d4
Contents?: true
Size: 1.24 KB
Versions: 9
Compression:
Stored size: 1.24 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 } end end end
Version data entries
9 entries across 9 versions & 1 rubygems