Class: PSGC::Region

Inherits:
Struct
  • Object
show all
Defined in:
lib/psgc/region.rb

Constant Summary collapse

REGION_DATA =
File.join(PSGC::DATA_DIR, 'regions.csv')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Region

Returns a new instance of Region.



5
6
7
# File 'lib/psgc/region.rb', line 5

def initialize(*args)
  super(*args)
end

Instance Attribute Details

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



4
5
6
# File 'lib/psgc/region.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/psgc/region.rb', line 4

def name
  @name
end

Class Method Details

.[](id) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/psgc/region.rb', line 16

def [](id)
  case
  when id.kind_of?(Fixnum)
    map_by_num[id]
  when id.kind_of?(String)
    map_by_string[id]
  else
    raise "\"#{id}\" expected either String or Fixnum (was #{id.class})"
  end
end

.allObject



12
13
14
# File 'lib/psgc/region.rb', line 12

def all
  @@all ||= load_regions
end

Instance Method Details

#codeObject



45
46
47
# File 'lib/psgc/region.rb', line 45

def code
  "#{id}0000000"
end

#provincesObject



49
50
51
# File 'lib/psgc/region.rb', line 49

def provinces
  @provinces ||= load_provinces
end