Class: Knykode::Postcode

Inherits:
Object
  • Object
show all
Defined in:
lib/knykode/postcode.rb

Instance Method Summary collapse

Instance Method Details

#number_of_postofficesObject



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

#postcodesObject



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

#postofficesObject

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_outputObject

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