Class: Knykode::Postcode
- Inherits:
-
Object
- Object
- Knykode::Postcode
- Defined in:
- lib/knykode/postcode.rb
Instance Method Summary collapse
- #number_of_postoffices ⇒ Object
- #postcode(postoffice) ⇒ Object
- #postcodes ⇒ Object
- #postoffice(postcode) ⇒ Object
-
#postoffices ⇒ Object
returns an array of all post-offices in the record.
-
#yml_output ⇒ Object
Returns a YML formated output of all the postcodes and postoffices.
Instance Method Details
#number_of_postoffices ⇒ Object
22 23 24 |
# File 'lib/knykode/postcode.rb', line 22 def number_of_postoffices postcodes.size end |
#postcode(postoffice) ⇒ Object
14 15 16 |
# File 'lib/knykode/postcode.rb', line 14 def postcode(postoffice) check_nil(postcodes[postoffice]) end |
#postcodes ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/knykode/postcode.rb', line 6 def postcodes codes = Parser.new.read("data/postcodes.txt"). map{|entry|entry.chomp}. map{|postcode| postcode. split(',')}.flatten Hash[*codes] end |
#postoffice(postcode) ⇒ Object
18 19 20 |
# File 'lib/knykode/postcode.rb', line 18 def postoffice(postcode) check_nil(postcodes.invert[postcode]) end |
#postoffices ⇒ Object
returns an array of all post-offices in the record.
27 28 29 |
# File 'lib/knykode/postcode.rb', line 27 def postoffices postcodes.keys.sort end |
#yml_output ⇒ Object
Returns a YML formated output of all the postcodes and postoffices
32 33 34 |
# File 'lib/knykode/postcode.rb', line 32 def yml_output postcodes.to_yaml end |