Class: Everypolitician::Legislature

Inherits:
Object
  • Object
show all
Defined in:
lib/everypolitician/legislature.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(legislature_data, country) ⇒ Legislature

Returns a new instance of Legislature.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/everypolitician/legislature.rb', line 22

def initialize(legislature_data, country)
  @name = legislature_data[:name]
  @slug = legislature_data[:slug]
  @lastmod_str = legislature_data[:lastmod]
  @person_count = legislature_data[:person_count]
  @sha = legislature_data[:sha]
  @statement_count = legislature_data[:statement_count]
  @popolo_url = legislature_data[:popolo_url]
  @raw_data = legislature_data
  @country = country
  @type = legislature_data[:type]
end

Instance Attribute Details

#countryObject (readonly)

Returns the value of attribute country.



11
12
13
# File 'lib/everypolitician/legislature.rb', line 11

def country
  @country
end

#lastmod_strObject (readonly)

Returns the value of attribute lastmod_str.



8
9
10
# File 'lib/everypolitician/legislature.rb', line 8

def lastmod_str
  @lastmod_str
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/everypolitician/legislature.rb', line 6

def name
  @name
end

#person_countObject (readonly)

Returns the value of attribute person_count.



9
10
11
# File 'lib/everypolitician/legislature.rb', line 9

def person_count
  @person_count
end

#popolo_urlObject (readonly)

Returns the value of attribute popolo_url.



14
15
16
# File 'lib/everypolitician/legislature.rb', line 14

def popolo_url
  @popolo_url
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



12
13
14
# File 'lib/everypolitician/legislature.rb', line 12

def raw_data
  @raw_data
end

#shaObject (readonly)

Returns the value of attribute sha.



10
11
12
# File 'lib/everypolitician/legislature.rb', line 10

def sha
  @sha
end

#slugObject (readonly)

Returns the value of attribute slug.



7
8
9
# File 'lib/everypolitician/legislature.rb', line 7

def slug
  @slug
end

#statement_countObject (readonly)

Returns the value of attribute statement_count.



13
14
15
# File 'lib/everypolitician/legislature.rb', line 13

def statement_count
  @statement_count
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/everypolitician/legislature.rb', line 15

def type
  @type
end

Class Method Details

.find(country_slug, legislature_slug) ⇒ Object



17
18
19
20
# File 'lib/everypolitician/legislature.rb', line 17

def self.find(country_slug, legislature_slug)
  country = Country.find(country_slug)
  country && country.legislature(legislature_slug)
end

.from_sources_dir(dir) ⇒ Object



57
58
59
60
# File 'lib/everypolitician/legislature.rb', line 57

def self.from_sources_dir(dir)
  @index_by_sources ||= EveryPolitician.countries.map(&:legislatures).flatten.group_by(&:directory)
  @index_by_sources[dir][0]
end

Instance Method Details

#[](key) ⇒ Object



35
36
37
# File 'lib/everypolitician/legislature.rb', line 35

def [](key)
  raw_data[key]
end

#directoryObject



49
50
51
# File 'lib/everypolitician/legislature.rb', line 49

def directory
  @directory = raw_data[:sources_directory].split('/')[1, 2].join('/')
end

#lastmodObject



62
63
64
# File 'lib/everypolitician/legislature.rb', line 62

def lastmod
  Time.at(lastmod_str.to_i).gmtime
end

#latest_termObject



53
54
55
# File 'lib/everypolitician/legislature.rb', line 53

def latest_term
  @latest_term ||= popolo.latest_term
end

#legislative_periodsObject



43
44
45
46
47
# File 'lib/everypolitician/legislature.rb', line 43

def legislative_periods
  @legislative_periods ||= raw_data[:legislative_periods].map do |lp|
    LegislativePeriod.new(lp, self, country)
  end
end

#names_urlObject



66
67
68
69
# File 'lib/everypolitician/legislature.rb', line 66

def names_url
  'https://cdn.rawgit.com/everypolitician/everypolitician-data/%s/%s' %
    [sha, raw_data[:names]]
end

#popoloObject



39
40
41
# File 'lib/everypolitician/legislature.rb', line 39

def popolo
  @popolo ||= Everypolitician::Popolo.parse(open(popolo_url).read)
end