Module: Legislation::UK

Defined in:
lib/legislation_uk.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.find(title, number = nil) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/legislation_uk.rb', line 216

def self.find title, number=nil
  begin
    number_part = number ? "&number=#{number}" : ''
    search_url = "http://www.legislation.gov.uk/id?title=#{URI.escape(title)}#{number_part}"
    xml = Legislation::UK.open_uri(search_url)
    to_object(xml)
  rescue Exception => e
    puts 'error retrieving: ' + search_url
    puts e.class.name
    puts e.to_s
    raise e
    nil
  end
end

.open_uri(uri) ⇒ Object



202
203
204
# File 'lib/legislation_uk.rb', line 202

def self.open_uri uri
  open(uri).read
end

.to_object(xml) ⇒ Object



206
207
208
209
210
211
212
213
214
# File 'lib/legislation_uk.rb', line 206

def self.to_object xml
  xml.gsub!(' Type=',' TheType=')
  xml.gsub!('dc:type','dc:the_type')
  hash = Hash.from_xml(xml)
  namespace = LegislationUK
  legislation = Morph.from_hash(hash, namespace)
  legislation.populate
  legislation
end