Class: GetYourRep::GoogleRep

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

Overview

Parses rep information from Google response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GoogleRep

Sets array attributes to empty arrays and and builds other attributes from options hash.



25
26
27
28
29
30
31
32
# File 'lib/get_your_rep/responses/google_rep.rb', line 25

def initialize(options = {})
  self.phones   = []
  self.emails   = []
  self.urls     = []
  self.address  = []
  self.channels = []
  super
end

Instance Attribute Details

#addressObject

An array of office addresses to be passes to a GoogleOffice instance for parsing. Default = []



14
15
16
# File 'lib/get_your_rep/responses/google_rep.rb', line 14

def address
  @address
end

#channelsObject

An array of social media handles. Default = []



16
17
18
# File 'lib/get_your_rep/responses/google_rep.rb', line 16

def channels
  @channels
end

#emailsObject

An array of email addresses. Default = []



10
11
12
# File 'lib/get_your_rep/responses/google_rep.rb', line 10

def emails
  @emails
end

#hashObject

Passes the GetYourRep::Representative constructor hash to different methods for assembly.



18
19
20
# File 'lib/get_your_rep/responses/google_rep.rb', line 18

def hash
  @hash
end

#office_nameObject

The office name must be parsed from an array passed to the build_hash method. the office_array is an array of hashes and is a sibling to the officials array from which the rep info is parsed.



22
23
24
# File 'lib/get_your_rep/responses/google_rep.rb', line 22

def office_name
  @office_name
end

#phonesObject

An array of phone numbers. Default = []



8
9
10
# File 'lib/get_your_rep/responses/google_rep.rb', line 8

def phones
  @phones
end

#urlsObject

An array of websites. Default = []



12
13
14
# File 'lib/get_your_rep/responses/google_rep.rb', line 12

def urls
  @urls
end

Instance Method Details

#build_hash(offices_array, index) ⇒ Object

Build a hash from attributes to be passed to the GetYourRep::Representative constructor method.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/get_your_rep/responses/google_rep.rb', line 35

def build_hash(offices_array, index)
  find_office_name(offices_array, index)
  self.hash = { name:             name,
                office:           office_name,
                party:            party,
                phones:           phones,
                office_locations: office_locations,
                email:            emails,
                url:              url,
                photo:            photoUrl }
  parse_channels
  hash
end