legislation-uk 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/README +11 -3
- data/lib/legislation_uk.rb +69 -15
- metadata +20 -22
- data/Manifest +0 -5
- data/Rakefile +0 -32
- data/legislation-uk.gemspec +0 -37
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -21,16 +21,24 @@ Should be up at rubyforge, so to install:
|
|
21
21
|
|
22
22
|
Can be used from command line if you run irb:
|
23
23
|
|
24
|
-
irb
|
24
|
+
> irb
|
25
25
|
|
26
26
|
require 'rubygems'
|
27
27
|
require 'legislation_uk'
|
28
28
|
|
29
29
|
legislation = Legislation::UK.find('Channel Tunnel Rail Link Act 1996')
|
30
30
|
|
31
|
-
legislation.
|
31
|
+
legislation.title #=> "Channel Tunnel Rail Link Act 1996"
|
32
32
|
|
33
|
-
legislation.
|
33
|
+
legislation.legislation_url #=> "http://www.legislation.gov.uk/ukpga/1996/61"
|
34
|
+
|
35
|
+
legislation.opsi_url #=> "http://www.opsi.gov.uk/acts/acts1996/ukpga_19960061_en_1"
|
36
|
+
|
37
|
+
legislation.statutelaw_url #=> "http://www.statutelaw.gov.uk/documents/1996/61/ukpga/c61"
|
38
|
+
|
39
|
+
legislation.parts.size #=> 3
|
40
|
+
|
41
|
+
legislation.parts.collect(&:number) #=> ["Part I", "Part II", "Part III"]
|
34
42
|
|
35
43
|
legislation.parts.collect(&:title) #=> ["The Channel Tunnel Rail Link",
|
36
44
|
# "The A2 and M2 Improvement Works",
|
data/lib/legislation_uk.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'activesupport'
|
2
1
|
require 'morph'
|
2
|
+
require 'hpricot'
|
3
3
|
require 'open-uri'
|
4
4
|
|
5
5
|
module LegislationUK
|
@@ -10,19 +10,71 @@ module LegislationUK
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
module ItemNumber
|
14
|
+
def number
|
15
|
+
contents_number
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
13
19
|
class Legislation
|
14
20
|
include Morph
|
21
|
+
|
22
|
+
def self.open_uri uri
|
23
|
+
open(uri).read
|
24
|
+
end
|
25
|
+
|
26
|
+
def legislation_url
|
27
|
+
document_uri
|
28
|
+
end
|
29
|
+
|
30
|
+
def statutelaw_url
|
31
|
+
if legislation_url[%r|http://www.legislation.gov.uk/(.+)/(\d\d\d\d)/(\d+)|]
|
32
|
+
type = $1
|
33
|
+
year = $2
|
34
|
+
chapter = $3
|
35
|
+
"http://www.statutelaw.gov.uk/documents/#{year}/#{chapter}/#{type}/c#{chapter}"
|
36
|
+
else
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def title
|
42
|
+
metadata.title
|
43
|
+
end
|
44
|
+
|
15
45
|
def parts
|
16
46
|
contents ? contents.contents_parts : []
|
17
47
|
end
|
48
|
+
|
49
|
+
def opsi_url
|
50
|
+
unless @opsi_url
|
51
|
+
search_url = "http://search.opsi.gov.uk/search?q=#{URI.escape(title)}&output=xml_no_dtd&client=opsisearch_semaphore&site=opsi_collection"
|
52
|
+
begin
|
53
|
+
doc = Hpricot.XML Legislation.open_uri(search_url)
|
54
|
+
url = nil
|
55
|
+
|
56
|
+
(doc/'R/T').each do |result|
|
57
|
+
unless url
|
58
|
+
term = result.inner_text.gsub(/<[^>]+>/,'').strip
|
59
|
+
url = result.at('../U/text()').to_s if(title == term || term.starts_with?(title))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
@opsi_url = url
|
64
|
+
rescue Exception => e
|
65
|
+
puts 'error retrieving: ' + search_url
|
66
|
+
puts e.class.name
|
67
|
+
puts e.to_s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
@opsi_url
|
71
|
+
end
|
18
72
|
end
|
19
73
|
|
20
74
|
class ContentsPart
|
21
75
|
include Morph
|
22
76
|
include Title
|
23
|
-
|
24
|
-
contents_number
|
25
|
-
end
|
77
|
+
include ItemNumber
|
26
78
|
def blocks
|
27
79
|
contents_pblocks ? contents_pblocks : []
|
28
80
|
end
|
@@ -31,6 +83,16 @@ module LegislationUK
|
|
31
83
|
class ContentsPblock
|
32
84
|
include Morph
|
33
85
|
include Title
|
86
|
+
|
87
|
+
def sections
|
88
|
+
contents_items
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class ContentsItem
|
93
|
+
include Morph
|
94
|
+
include Title
|
95
|
+
include ItemNumber
|
34
96
|
end
|
35
97
|
end
|
36
98
|
|
@@ -38,7 +100,7 @@ end
|
|
38
100
|
# See README for usage documentation.
|
39
101
|
module Legislation
|
40
102
|
module UK
|
41
|
-
VERSION = "0.0.
|
103
|
+
VERSION = "0.0.2"
|
42
104
|
|
43
105
|
def self.open_uri uri
|
44
106
|
open(uri).read
|
@@ -53,9 +115,9 @@ module Legislation
|
|
53
115
|
end
|
54
116
|
|
55
117
|
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
118
|
begin
|
119
|
+
number_part = number ? "&number=#{number}" : ''
|
120
|
+
search_url = "http://www.legislation.gov.uk/id?title=#{URI.escape(title)}#{number_part}"
|
59
121
|
xml = Legislation::UK.open_uri(search_url)
|
60
122
|
to_object(xml)
|
61
123
|
rescue Exception => e
|
@@ -67,13 +129,5 @@ module Legislation
|
|
67
129
|
end
|
68
130
|
end
|
69
131
|
|
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
132
|
end
|
79
133
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: legislation-uk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob McKinnon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-29 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -23,47 +23,45 @@ dependencies:
|
|
23
23
|
version: 0.2.7
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
26
|
+
name: hpricot
|
27
27
|
type: :runtime
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.8.1
|
34
34
|
version:
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: Ruby API for accessing UK Legislation hosted at http://www.legislation.gov.uk/
|
46
|
+
email: rob ~@nospam@~ rubyforge.org
|
40
47
|
executables: []
|
41
48
|
|
42
49
|
extensions: []
|
43
50
|
|
44
51
|
extra_rdoc_files:
|
45
52
|
- README
|
46
|
-
- CHANGELOG
|
47
53
|
files:
|
48
|
-
- README
|
49
54
|
- CHANGELOG
|
50
|
-
-
|
55
|
+
- README
|
51
56
|
- lib/legislation_uk.rb
|
52
|
-
- Manifest
|
53
|
-
- legislation-uk.gemspec
|
54
57
|
has_rdoc: true
|
55
|
-
homepage:
|
58
|
+
homepage: http://github.com/robmckinnon/legislation-uk
|
56
59
|
licenses: []
|
57
60
|
|
58
61
|
post_install_message:
|
59
62
|
rdoc_options:
|
60
|
-
- --line-numbers
|
61
|
-
- --inline-source
|
62
|
-
- --title
|
63
|
-
- Legislation-uk
|
64
63
|
- --main
|
65
64
|
- README
|
66
|
-
- --inline-source
|
67
65
|
require_paths:
|
68
66
|
- lib
|
69
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -76,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
74
|
requirements:
|
77
75
|
- - ">="
|
78
76
|
- !ruby/object:Gem::Version
|
79
|
-
version: "
|
77
|
+
version: "0"
|
80
78
|
version:
|
81
79
|
requirements: []
|
82
80
|
|
@@ -84,6 +82,6 @@ rubyforge_project: legislation-uk
|
|
84
82
|
rubygems_version: 1.3.5
|
85
83
|
signing_key:
|
86
84
|
specification_version: 3
|
87
|
-
summary:
|
85
|
+
summary: Ruby API for http://www.legislation.gov.uk/
|
88
86
|
test_files: []
|
89
87
|
|
data/Manifest
DELETED
data/Rakefile
DELETED
@@ -1,32 +0,0 @@
|
|
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
|
data/legislation-uk.gemspec
DELETED
@@ -1,37 +0,0 @@
|
|
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
|