Class: Thailand::Region

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

Direct Known Subclasses

Country, District, Province

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}, parent = nil) ⇒ Region

Returns a new instance of Region.



9
10
11
12
# File 'lib/thailand/region.rb', line 9

def initialize(data = {}, parent = nil)
  @code = data['code']
  @parent = parent
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



7
8
9
# File 'lib/thailand/region.rb', line 7

def code
  @code
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/thailand/region.rb', line 7

def parent
  @parent
end

Instance Method Details

#<=>(other) ⇒ Object



56
57
58
# File 'lib/thailand/region.rb', line 56

def <=>(other)
  name <=> other.name
end

#inspectObject



43
44
45
# File 'lib/thailand/region.rb', line 43

def inspect
  "#<#{self.class} code: \"#{code}\", name: \"#{name}\">"
end

#nameObject



14
15
16
# File 'lib/thailand/region.rb', line 14

def name
  Thailand.i18n_backend.translate(path('name'))
end

#path(suffix = nil) ⇒ Object

Return a path string for this region. Useful for use with I18n Returns a string in the format “thailand.$PARENT_CODE.$REGION_CODE”, such as “thailand.10.1001”. The number of segments is the depth of the region plus one



37
38
39
40
41
# File 'lib/thailand/region.rb', line 37

def path(suffix = nil)
  base = "#{@parent.path}.#{subregion_directory}"
  base << ".#{suffix}" if suffix
  base
end

#reset!Object

Clears the subregion cache



52
53
54
# File 'lib/thailand/region.rb', line 52

def reset!
  @subregions = nil
end

#subregion_classObject



30
31
32
# File 'lib/thailand/region.rb', line 30

def subregion_class
  Region
end

#subregion_data_pathObject



26
27
28
# File 'lib/thailand/region.rb', line 26

def subregion_data_path
  @parent.subregion_data_path.sub('.yml', "/#{subregion_directory}.yml")
end

#subregionsObject



18
19
20
# File 'lib/thailand/region.rb', line 18

def subregions
  @subregions ||= load_subregions
end

#subregions?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/thailand/region.rb', line 22

def subregions?
  !subregions.empty?
end

#to_sObject



47
48
49
# File 'lib/thailand/region.rb', line 47

def to_s
  name
end