assembly_wales 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Assembly Wales
2
+
3
+ Ruby gem to connect to the Assembly Wales XML feed
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ require 'assembly_wales'
9
+
10
+ date = Date.parse('2013-02-20')
11
+
12
+ record = AssemblyWales::Plenary.new(date)
13
+ ```
14
+
15
+ contributions in the date are stored an Array of AssemblyWales::Speech modules
16
+
17
+ `record.speeches`
18
+
19
+ Any field from the XML can be called from each speech element
20
+
21
+ ```
22
+ record.speeches.each do |speech|
23
+ speech.contribution_verbatim
24
+ end
25
+ ```
26
+
27
+ see [XML feed](http://www.assemblywales.org/docs/rop_xml/130220_plenary_bilingual.xml) for details
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.test_files = FileList['spec/lib/assembly_wales/*_spec.rb']
5
+ t.verbose = true
6
+ end
7
+
8
+ task :default => :test
@@ -0,0 +1,44 @@
1
+
2
+ # -*- encoding: utf-8 -*-
3
+ $:.push('lib')
4
+ require "assembly_wales/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "assembly_wales"
8
+ s.version = AssemblyWales::VERSION
9
+ s.date = "2013-02-25"
10
+ s.summary = "A Gem that consumes data from the Welsh Assembly"
11
+ s.email = "sam@samknight.co.uk"
12
+ s.homepage = "http://github.com/samknight/assembly_wales"
13
+ s.authors = ['Sam Knight']
14
+
15
+ s.description = "A Gem that consumes data from the Welsh Assembly"
16
+
17
+ dependencies = [
18
+ [:runtime, "httparty"],
19
+ [:development, "minitest"],
20
+ [:development, "webmock"],
21
+ [:development, "vcr"],
22
+ [:development, "turn"],
23
+ [:development, "rake"],
24
+ ]
25
+
26
+ s.files = Dir['**/*']
27
+ s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
28
+ s.executables = Dir['bin/*'].map { |f| File.basename(f) }
29
+ s.require_paths = ["lib"]
30
+
31
+
32
+ ## Make sure you can build the gem on older versions of RubyGems too:
33
+ s.rubygems_version = "2.0.0"
34
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
35
+ s.specification_version = 3 if s.respond_to? :specification_version
36
+
37
+ dependencies.each do |type, name, version|
38
+ if s.respond_to?("add_#{type}_dependency")
39
+ s.send("add_#{type}_dependency", name, version)
40
+ else
41
+ s.add_dependency(name, version)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ module AssemblyWales
2
+ BASE_URL = 'http://www.assemblywales.org/docs/rop_xml/'
3
+ class Plenary
4
+
5
+ attr_accessor :date, :record, :speeches
6
+
7
+ # Public: Retrieve a Plenary record
8
+ def initialize(date)
9
+ @date = date
10
+ @record = parse_xml(build_url(date))
11
+ @speeches = parse_speeches
12
+ end
13
+
14
+ private
15
+
16
+ def build_url(date)
17
+ BASE_URL + date.strftime('%y%m%d') + '_plenary_bilingual.xml'
18
+ end
19
+
20
+ def parse_xml(url)
21
+ HTTParty.get(url).first[1].first[1]
22
+ end
23
+
24
+ def parse_speeches
25
+ collect_speeches = []
26
+ record.each do |raw_speech|
27
+ speech = {}
28
+ raw_speech.each_pair do |k,v|
29
+ speech.merge!(k.downcase => v)
30
+ end
31
+ collect_speeches << AssemblyWales::Speech.new(speech)
32
+ end
33
+ collect_speeches
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ module AssemblyWales
2
+ class Speech
3
+ attr_accessor :content
4
+
5
+ def initialize(content)
6
+ @content = content
7
+ end
8
+
9
+ def method_missing(name, *args, &block)
10
+ if content.has_key?(name.to_s)
11
+ content[name.to_s]
12
+ else
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module AssemblyWales
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'httparty'
2
+
3
+ Dir[File.dirname(__FILE__) + '/assembly_wales/*.rb'].each do |file|
4
+ require file
5
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../lib/qssembly_wales'
2
+
3
+ require 'minitest/autorun'
4
+ require 'turn'
5
+ require 'vcr'
6
+ require 'webmock/minitest'
7
+
8
+ Turn.config do |c|
9
+ c.format = :dot
10
+ end
11
+
12
+ VCR.configure do |c|
13
+ c.cassette_library_dir = 'spec/fixtures/assembly_wales_cassettes'
14
+ c.hook_into :webmock
15
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assembly_wales
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sam Knight
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: webmock
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: vcr
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: turn
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A Gem that consumes data from the Welsh Assembly
111
+ email: sam@samknight.co.uk
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files: []
115
+ files:
116
+ - assembly_wales.gemspec
117
+ - Gemfile
118
+ - lib/assembly_wales/plenary.rb
119
+ - lib/assembly_wales/speech.rb
120
+ - lib/assembly_wales/version.rb
121
+ - lib/assembly_wales.rb
122
+ - Rakefile
123
+ - README.md
124
+ - spec/spec_helper.rb
125
+ homepage: http://github.com/samknight/assembly_wales
126
+ licenses: []
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 1.8.25
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: A Gem that consumes data from the Welsh Assembly
149
+ test_files:
150
+ - spec/spec_helper.rb