legislation-uk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v0.0.1 initial alpha release
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ README
2
+ CHANGELOG
3
+ Rakefile
4
+ lib/legislation_uk.rb
5
+ Manifest
data/README ADDED
@@ -0,0 +1,37 @@
1
+ Ruby API to the restful UK legislation XML service hosted at: http://www.legislation.gov.uk/
2
+
3
+ = Warning: API under development
4
+
5
+ The legislation-uk API is in early development so it may change slightly over
6
+ time. It should be in working order, so please give it a test spin!
7
+
8
+ The source code is hosted at github. Feel free to fork the code if you have
9
+ something to contribute:
10
+
11
+ http://github.com/robmckinnon/legislation-uk
12
+
13
+
14
+ == Install as a Gem
15
+
16
+ Should be up at rubyforge, so to install:
17
+
18
+ sudo gem install legislation-uk
19
+
20
+ == To use
21
+
22
+ Can be used from command line if you run irb:
23
+
24
+ irb
25
+
26
+ require 'rubygems'
27
+ require 'legislation_uk'
28
+
29
+ legislation = Legislation::UK.find('Channel Tunnel Rail Link Act 1996')
30
+
31
+ legislation.parts.size #=> 3
32
+
33
+ legislation.parts.collect(&:number) #=> ["Part I", "Part II", "Part III"]
34
+
35
+ legislation.parts.collect(&:title) #=> ["The Channel Tunnel Rail Link",
36
+ # "The A2 and M2 Improvement Works",
37
+ # "Miscellaneous and General"]
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'lib/legislation_uk'
3
+
4
+ begin
5
+ require 'spec'
6
+ rescue LoadError
7
+ puts "\nYou need to install the rspec gem to perform meta operations on this gem"
8
+ puts " sudo gem install rspec\n"
9
+ end
10
+
11
+ begin
12
+ require 'echoe'
13
+
14
+ Echoe.new("legislation-uk", Legislation::UK::VERSION) do |m|
15
+ m.author = ["Rob McKinnon"]
16
+ m.email = ["rob ~@nospam@~ rubyforge.org"]
17
+ m.description = File.readlines("README").first
18
+ m.rubyforge_name = "legislation-uk"
19
+ m.rdoc_options << '--inline-source'
20
+ m.dependencies = ["morph >=0.2.7", "activesupport >=2.0.2"]
21
+ m.rdoc_pattern = ["README", "CHANGELOG"] #, "LICENSE"]
22
+ end
23
+
24
+ rescue LoadError
25
+ puts "\nYou need to install the echoe gem to perform meta operations on this gem"
26
+ puts " sudo gem install echoe\n\n"
27
+ end
28
+
29
+ desc "Open an irb session preloaded with this library"
30
+ task :console do
31
+ sh "irb -rubygems -r ./lib/legislation_uk.rb"
32
+ end
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{legislation-uk}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Rob McKinnon"]
9
+ s.date = %q{2009-09-24}
10
+ s.description = %q{Ruby API to the restful UK legislation XML service hosted at: http://www.legislation.gov.uk/
11
+ }
12
+ s.email = ["rob ~@nospam@~ rubyforge.org"]
13
+ s.extra_rdoc_files = ["README", "CHANGELOG"]
14
+ s.files = ["README", "CHANGELOG", "Rakefile", "lib/legislation_uk.rb", "Manifest", "legislation-uk.gemspec"]
15
+ s.homepage = %q{}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Legislation-uk", "--main", "README", "--inline-source"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{legislation-uk}
19
+ s.rubygems_version = %q{1.3.5}
20
+ s.summary = %q{Ruby API to the restful UK legislation XML service hosted at: http://www.legislation.gov.uk/}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<morph>, [">= 0.2.7"])
28
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
29
+ else
30
+ s.add_dependency(%q<morph>, [">= 0.2.7"])
31
+ s.add_dependency(%q<activesupport>, [">= 2.0.2"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<morph>, [">= 0.2.7"])
35
+ s.add_dependency(%q<activesupport>, [">= 2.0.2"])
36
+ end
37
+ end
@@ -0,0 +1,79 @@
1
+ require 'activesupport'
2
+ require 'morph'
3
+ require 'open-uri'
4
+
5
+ module LegislationUK
6
+
7
+ module Title
8
+ def title
9
+ contents_title.is_a?(String) ? contents_title.strip : contents_title.title.strip
10
+ end
11
+ end
12
+
13
+ class Legislation
14
+ include Morph
15
+ def parts
16
+ contents ? contents.contents_parts : []
17
+ end
18
+ end
19
+
20
+ class ContentsPart
21
+ include Morph
22
+ include Title
23
+ def number
24
+ contents_number
25
+ end
26
+ def blocks
27
+ contents_pblocks ? contents_pblocks : []
28
+ end
29
+ end
30
+
31
+ class ContentsPblock
32
+ include Morph
33
+ include Title
34
+ end
35
+ end
36
+
37
+
38
+ # See README for usage documentation.
39
+ module Legislation
40
+ module UK
41
+ VERSION = "0.0.1"
42
+
43
+ def self.open_uri uri
44
+ open(uri).read
45
+ end
46
+
47
+ def self.to_object xml
48
+ xml.gsub!(' Type=',' TheType=')
49
+ xml.gsub!('dc:type','dc:the_type')
50
+ hash = Hash.from_xml(xml)
51
+ namespace = LegislationUK
52
+ Morph.from_hash(hash, namespace)
53
+ end
54
+
55
+ def self.find title, number=nil
56
+ number_part = number ? "&number=#{number}" : ''
57
+ search_url = "http://www.legislation.gov.uk/id?title=#{URI.escape(title)}#{number_part}"
58
+ begin
59
+ xml = Legislation::UK.open_uri(search_url)
60
+ to_object(xml)
61
+ rescue Exception => e
62
+ puts 'error retrieving: ' + search_url
63
+ puts e.class.name
64
+ puts e.to_s
65
+ raise e
66
+ nil
67
+ end
68
+ end
69
+
70
+ def self.find_uri title, number=nil
71
+ legislation = find(title, number)
72
+ if legislation
73
+ legislation.document_uri
74
+ else
75
+ nil
76
+ end
77
+ end
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: legislation-uk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rob McKinnon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-24 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: morph
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.7
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.2
34
+ version:
35
+ description: |
36
+ Ruby API to the restful UK legislation XML service hosted at: http://www.legislation.gov.uk/
37
+
38
+ email:
39
+ - rob ~@nospam@~ rubyforge.org
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - README
46
+ - CHANGELOG
47
+ files:
48
+ - README
49
+ - CHANGELOG
50
+ - Rakefile
51
+ - lib/legislation_uk.rb
52
+ - Manifest
53
+ - legislation-uk.gemspec
54
+ has_rdoc: true
55
+ homepage: ""
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --line-numbers
61
+ - --inline-source
62
+ - --title
63
+ - Legislation-uk
64
+ - --main
65
+ - README
66
+ - --inline-source
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "1.2"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: legislation-uk
84
+ rubygems_version: 1.3.5
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: "Ruby API to the restful UK legislation XML service hosted at: http://www.legislation.gov.uk/"
88
+ test_files: []
89
+