Class: Thailand::Region
- Inherits:
-
Object
show all
- Defined in:
- lib/thailand/region.rb
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
#code ⇒ Object
Returns the value of attribute code.
7
8
9
|
# File 'lib/thailand/region.rb', line 7
def code
@code
end
|
#parent ⇒ Object
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
|
#inspect ⇒ Object
43
44
45
|
# File 'lib/thailand/region.rb', line 43
def inspect
"#<#{self.class} code: \"#{code}\", name: \"#{name}\">"
end
|
#name ⇒ Object
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_class ⇒ Object
30
31
32
|
# File 'lib/thailand/region.rb', line 30
def subregion_class
Region
end
|
#subregion_data_path ⇒ Object
26
27
28
|
# File 'lib/thailand/region.rb', line 26
def subregion_data_path
@parent.subregion_data_path.sub('.yml', "/#{subregion_directory}.yml")
end
|
#subregions ⇒ Object
18
19
20
|
# File 'lib/thailand/region.rb', line 18
def subregions
@subregions ||= load_subregions
end
|
#subregions? ⇒ Boolean
22
23
24
|
# File 'lib/thailand/region.rb', line 22
def subregions?
!subregions.empty?
end
|
#to_s ⇒ Object
47
48
49
|
# File 'lib/thailand/region.rb', line 47
def to_s
name
end
|