Class: AreaCN::Area
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #children_codes ⇒ Object
- #children_names ⇒ Object
- #city? ⇒ Boolean
- #code ⇒ Object
- #district? ⇒ Boolean
-
#initialize(area = {}) ⇒ Area
constructor
area is a json area from areas.json file.
- #parent_code ⇒ Object
- #province? ⇒ Boolean
- #to_hash ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
7 8 9 |
# File 'lib/area_cn/area.rb', line 7 def children @children end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/area_cn/area.rb', line 7 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
8 9 10 |
# File 'lib/area_cn/area.rb', line 8 def parent @parent end |
Instance Method Details
#<=>(other) ⇒ Object
45 46 47 |
# File 'lib/area_cn/area.rb', line 45 def <=>(other) code <=> other.code end |
#children_codes ⇒ Object
29 30 31 |
# File 'lib/area_cn/area.rb', line 29 def children_codes @children_codes ||= children.map { |child| child.code } end |
#children_names ⇒ Object
25 26 27 |
# File 'lib/area_cn/area.rb', line 25 def children_names @children_names ||= children.map(&:name) end |
#city? ⇒ Boolean
37 38 39 |
# File 'lib/area_cn/area.rb', line 37 def city? @code.prefix.length == 4 end |
#code ⇒ Object
17 18 19 |
# File 'lib/area_cn/area.rb', line 17 def code @code.value end |
#district? ⇒ Boolean
41 42 43 |
# File 'lib/area_cn/area.rb', line 41 def district? @code.prefix.length == 6 end |
#parent_code ⇒ Object
21 22 23 |
# File 'lib/area_cn/area.rb', line 21 def parent_code @code.parent.code end |
#province? ⇒ Boolean
33 34 35 |
# File 'lib/area_cn/area.rb', line 33 def province? @code.prefix.length == 2 end |
#to_hash ⇒ Object
49 50 51 |
# File 'lib/area_cn/area.rb', line 49 def to_hash {name: name, code: code} end |
#to_json(*args) ⇒ Object
53 54 55 |
# File 'lib/area_cn/area.rb', line 53 def to_json(*args) to_hash.to_json(*args) end |