Class: Geocodio::CongressionalDistrict

Inherits:
Object
  • Object
show all
Defined in:
lib/geocodio/congressional_district.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload = {}) ⇒ CongressionalDistrict

Returns a new instance of CongressionalDistrict.


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/geocodio/congressional_district.rb', line 11

def initialize(payload = {})
  @name            = payload['name']
  @district_number = payload['district_number'].to_i
  @congress_number = payload['congress_number'].to_i
  @congress_years  = payload['congress_years']
  @proportion      = payload['proportion'].to_i

  @current_legislators = payload['current_legislators'].map do |legislator|
    Legislator.new(legislator)
  end
end

Instance Attribute Details

#congress_numberObject (readonly)

Returns the value of attribute congress_number


7
8
9
# File 'lib/geocodio/congressional_district.rb', line 7

def congress_number
  @congress_number
end

#current_legislatorsObject (readonly)

Returns the value of attribute current_legislators


9
10
11
# File 'lib/geocodio/congressional_district.rb', line 9

def current_legislators
  @current_legislators
end

#district_numberObject (readonly)

Returns the value of attribute district_number


6
7
8
# File 'lib/geocodio/congressional_district.rb', line 6

def district_number
  @district_number
end

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/geocodio/congressional_district.rb', line 5

def name
  @name
end

#proportionObject (readonly)

Returns the value of attribute proportion


8
9
10
# File 'lib/geocodio/congressional_district.rb', line 8

def proportion
  @proportion
end

Instance Method Details

#congress_yearsObject


23
24
25
26
# File 'lib/geocodio/congressional_district.rb', line 23

def congress_years
  first, last = @congress_years.split('-').map(&:to_i)
  first..last
end