Class: CivicInformation::RepresentativesResource::Office

Inherits:
Object
  • Object
show all
Defined in:
lib/civic_information/models/representatives_resource/office.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result_index:, office_json:, parent_resource_id:) ⇒ Office

Returns a new instance of Office.



6
7
8
9
10
11
12
13
14
15
# File 'lib/civic_information/models/representatives_resource/office.rb', line 6

def initialize(result_index:, office_json:, parent_resource_id:)
  @parent_resource_id = parent_resource_id
  @result_index = result_index
  @division_id = office_json['divisionId']
  @levels = office_json['levels'] || []
  @name = office_json['name']
  @roles = office_json['roles'] || []
  @sources = office_json['sources'] || []
  @official_indices = office_json['officialIndices'] || []
end

Instance Attribute Details

#division_idObject

Returns the value of attribute division_id.



3
4
5
# File 'lib/civic_information/models/representatives_resource/office.rb', line 3

def division_id
  @division_id
end

#levelsObject

Returns the value of attribute levels.



3
4
5
# File 'lib/civic_information/models/representatives_resource/office.rb', line 3

def levels
  @levels
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/civic_information/models/representatives_resource/office.rb', line 3

def name
  @name
end

#official_indicesObject

Returns the value of attribute official_indices.



3
4
5
# File 'lib/civic_information/models/representatives_resource/office.rb', line 3

def official_indices
  @official_indices
end

#result_indexObject

Returns the value of attribute result_index.



3
4
5
# File 'lib/civic_information/models/representatives_resource/office.rb', line 3

def result_index
  @result_index
end

#rolesObject

Returns the value of attribute roles.



3
4
5
# File 'lib/civic_information/models/representatives_resource/office.rb', line 3

def roles
  @roles
end

#sourcesObject

Returns the value of attribute sources.



3
4
5
# File 'lib/civic_information/models/representatives_resource/office.rb', line 3

def sources
  @sources
end

Instance Method Details

#divisionObject



23
24
25
26
27
# File 'lib/civic_information/models/representatives_resource/office.rb', line 23

def division
  parent_resource.divisions.find do |division|
    division.open_civic_data_id == division_id
  end
end

#officialsObject



17
18
19
20
21
# File 'lib/civic_information/models/representatives_resource/office.rb', line 17

def officials
  parent_resource.officials.select do |official|
    @official_indices.include? official.result_index
  end
end