Class: Carmen::Region
- Inherits:
-
Object
- Object
- Carmen::Region
- Defined in:
- lib/carmen/region.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(data = {}, parent = nil) ⇒ Region
constructor
A new instance of Region.
- #inspect ⇒ Object
- #name ⇒ Object
-
#path(suffix = nil) ⇒ Object
Return a path string for this region.
-
#reset! ⇒ Object
Clears the subregion cache.
- #subregion_class ⇒ Object
- #subregion_data_path ⇒ Object
- #subregions ⇒ Object
- #subregions? ⇒ Boolean
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data = {}, parent = nil) ⇒ Region
Returns a new instance of Region.
13 14 15 16 17 |
# File 'lib/carmen/region.rb', line 13 def initialize(data={}, parent=nil) @type = data['type'] @code = data['code'] @parent = parent end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
10 11 12 |
# File 'lib/carmen/region.rb', line 10 def code @code end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
11 12 13 |
# File 'lib/carmen/region.rb', line 11 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/carmen/region.rb', line 9 def type @type end |
Instance Method Details
#<=>(other) ⇒ Object
66 67 68 |
# File 'lib/carmen/region.rb', line 66 def <=>(other) name <=> other.name end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/carmen/region.rb', line 49 def inspect "<##{self.class} name=\"#{name}\" type=\"#{type}\">" end |
#name ⇒ Object
19 20 21 |
# File 'lib/carmen/region.rb', line 19 def name Carmen.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 “world.$PARENT_CODE.$REGION_CODE”, such as “world.us.il”. The number of segments is the depth of the region plus one.
43 44 45 46 47 |
# File 'lib/carmen/region.rb', line 43 def path(suffix=nil) base = "#{parent.path}.#{subregion_directory}" base << ".#{suffix.to_s}" if suffix base end |
#reset! ⇒ Object
Clears the subregion cache
62 63 64 |
# File 'lib/carmen/region.rb', line 62 def reset! @subregions = nil end |
#subregion_class ⇒ Object
35 36 37 |
# File 'lib/carmen/region.rb', line 35 def subregion_class Region end |
#subregion_data_path ⇒ Object
31 32 33 |
# File 'lib/carmen/region.rb', line 31 def subregion_data_path @parent.subregion_data_path.sub('.yml', "/#{subregion_directory}.yml") end |
#subregions ⇒ Object
23 24 25 |
# File 'lib/carmen/region.rb', line 23 def subregions @subregions ||= load_subregions.freeze end |
#subregions? ⇒ Boolean
27 28 29 |
# File 'lib/carmen/region.rb', line 27 def subregions? !subregions.empty? end |
#to_hash ⇒ Object
57 58 59 |
# File 'lib/carmen/region.rb', line 57 def to_hash { type: type, code: code, name: name, subregions: subregions } end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/carmen/region.rb', line 53 def to_s name end |