class Knykode::Postcode

Public Instance Methods

number_of_postoffices() click to toggle source
# File lib/knykode/postcode.rb, line 22
def number_of_postoffices
  postcodes.size
end
postcode(postoffice) click to toggle source
# File lib/knykode/postcode.rb, line 14
def postcode(postoffice)
  check_nil(postcodes[postoffice])
end
postcodes() click to toggle source
# 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) click to toggle source
# File lib/knykode/postcode.rb, line 18
def postoffice(postcode)
  check_nil(postcodes.invert[postcode])
end
postoffices() click to toggle source

returns an array of all post-offices in the record.

# File lib/knykode/postcode.rb, line 27
def postoffices
  postcodes.keys.sort
end
yml_output() click to toggle source

Returns a YML formated output of all the postcodes and postoffices

# File lib/knykode/postcode.rb, line 32
def yml_output
  postcodes.to_yaml
end

Private Instance Methods

check_nil(value) click to toggle source
# File lib/knykode/postcode.rb, line 37
def check_nil(value)
  value || "unknown"
end