everypolitician 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f5019b4f32557bebbe011a84ef324b25faedfa2
4
- data.tar.gz: 721813c2e6d40c2714c742520ccb7e569174303c
3
+ metadata.gz: c734f5270dbb5bb015317c50984d2556901bb325
4
+ data.tar.gz: 5f973a73b4e6f1bc867d8654e84ec170c6f84e55
5
5
  SHA512:
6
- metadata.gz: 7f648d3407c0ffd02073518f016a2c5f5964a75d98fbcf18aff88dc39344ef6f929fc7c4be4dbd4c58d43511b0e1e78d674b2f830bba2df22b5f8c397526b2a7
7
- data.tar.gz: ee7abeb616c7537c2b4111953051900ce4138369bd403b0f350eb5f1b844190f65f2bd0a3218c8f887cbceb375aff3dd801e7214ae3d65784dad8ed5b457ca8c
6
+ metadata.gz: 8ad9fece5fa48421aa809bbf5f749bf7cf87e053eb8d2def8ec77cef3672a5d37578639c7af7ce30fd4a27318ab274469d0ed3b440190a868ac2eb8bee7f1827
7
+ data.tar.gz: 32188629d9022a9d7bdfe275869e612be058a20afaa6179c2f5c7e1222c62bf080b96be22d49b889fd06dcb9e827cdbeb733c01c377b2a0373fa61b4c01d4cea
data/CHANGELOG.md CHANGED
@@ -3,6 +3,13 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [0.6.0] - 2016-01-29
7
+
8
+ ### Added
9
+
10
+ - There is now a `LegislativePeriod` class to represent each legislative period in a legislature. This has a `#csv` method to return a parsed version of the legislative periods CSV.
11
+ - You can now call `Legislature#country` to get the country for a legislature. Similarly you can call `LegislativePeriod#country` or `LegislativePeriod#legislature` to get the related objects.
12
+
6
13
  ## [0.5.0] - 2016-01-27
7
14
 
8
15
  ### Added
@@ -47,3 +54,4 @@ This project adheres to [Semantic Versioning](http://semver.org/).
47
54
  [0.3.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.2.0...v0.3.0
48
55
  [0.4.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.3.0...v0.4.0
49
56
  [0.5.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.4.0...v0.5.0
57
+ [0.6.0]: https://github.com/everypolitician/everypolitician-ruby/compare/v0.5.0...v0.6.0
@@ -2,6 +2,7 @@ require 'everypolitician/version'
2
2
  require 'json'
3
3
  require 'open-uri'
4
4
  require 'everypolitician/popolo'
5
+ require 'csv'
5
6
 
6
7
  module Everypolitician
7
8
  class Error < StandardError; end
@@ -63,13 +64,13 @@ module Everypolitician
63
64
  end
64
65
 
65
66
  def legislatures
66
- @legislatures ||= @raw_data[:legislatures].map { |l| Legislature.new(l) }
67
+ @legislatures ||= @raw_data[:legislatures].map { |l| Legislature.new(l, self) }
67
68
  end
68
69
 
69
70
  def legislature(query)
70
71
  query = { slug: query } if query.is_a?(String)
71
72
  legislature = legislatures.find { |l| query.all? { |k, v| l.__send__(k) == v } }
72
- fail Error, "Unknown legislature slug: #{slug}" if legislature.nil?
73
+ fail Error, "Unknown legislature: #{query}" if legislature.nil?
73
74
  legislature
74
75
  end
75
76
  end
@@ -80,19 +81,21 @@ module Everypolitician
80
81
  attr_reader :lastmod
81
82
  attr_reader :person_count
82
83
  attr_reader :sha
84
+ attr_reader :country
83
85
  attr_reader :raw_data
84
86
 
85
87
  def self.find(country_slug, legislature_slug)
86
88
  Country.find(country_slug).legislature(legislature_slug)
87
89
  end
88
90
 
89
- def initialize(legislature_data)
91
+ def initialize(legislature_data, country)
90
92
  @name = legislature_data[:name]
91
93
  @slug = legislature_data[:slug]
92
94
  @lastmod = legislature_data[:lastmod]
93
95
  @person_count = legislature_data[:person_count]
94
96
  @sha = legislature_data[:sha]
95
97
  @raw_data = legislature_data
98
+ @country = country
96
99
  end
97
100
 
98
101
  def popolo
@@ -105,7 +108,48 @@ module Everypolitician
105
108
  end
106
109
 
107
110
  def legislative_periods
108
- @legislative_periods ||= raw_data[:legislative_periods]
111
+ @legislative_periods ||= raw_data[:legislative_periods].map do |lp|
112
+ LegislativePeriod.new(lp, self, self.country)
113
+ end
114
+ end
115
+ end
116
+
117
+ class LegislativePeriod
118
+ attr_reader :id
119
+ attr_reader :name
120
+ attr_reader :slug
121
+ attr_reader :legislature
122
+ attr_reader :country
123
+ attr_reader :raw_data
124
+
125
+ def initialize(legislative_period_data, legislature, country)
126
+ @id = legislative_period_data[:id]
127
+ @name = legislative_period_data[:name]
128
+ @slug = legislative_period_data[:slug]
129
+ @legislature = legislature
130
+ @country = country
131
+ @raw_data = legislative_period_data
132
+ end
133
+
134
+ def start_date
135
+ @start_date ||= Date.parse(raw_data[:start_date])
136
+ end
137
+
138
+ def end_date
139
+ @end_date ||= Date.parse(raw_data[:end_date])
140
+ end
141
+
142
+ def csv_url
143
+ @csv_url ||= 'https://raw.githubusercontent.com/everypolitician' \
144
+ "/everypolitician-data/#{legislature.sha}/#{raw_data[:csv]}"
145
+ end
146
+
147
+ def csv
148
+ CSV.parse(open(csv_url).read, headers: true, header_converters: :symbol, converters: nil)
149
+ end
150
+
151
+ def [](key)
152
+ raw_data[key]
109
153
  end
110
154
  end
111
155
  end
@@ -1,3 +1,3 @@
1
1
  module Everypolitician
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everypolitician
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Mytton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-27 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: everypolitician-popolo