Class: Nayyar::Township
- Inherits:
-
Object
- Object
- Nayyar::Township
- Defined in:
- lib/nayyar/township.rb
Overview
Represents a Township in Myanmar
Constant Summary collapse
- ATTRIBUTES =
%i[ pcode name my_name ].freeze
- INDICES =
%w[pcode].freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
allow the values to be retrieved as an array.
- #district ⇒ Object
-
#initialize(data) ⇒ Township
constructor
A new instance of Township.
Constructor Details
#initialize(data) ⇒ Township
Returns a new instance of Township.
18 19 20 |
# File 'lib/nayyar/township.rb', line 18 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/nayyar/township.rb', line 5 def data @data end |
Class Method Details
.all ⇒ Object
43 44 45 |
# File 'lib/nayyar/township.rb', line 43 def all townships end |
.find_by(query) ⇒ Object
55 56 57 58 |
# File 'lib/nayyar/township.rb', line 55 def find_by(query) key = get_key(query) (index = send("#{key}_index".to_sym).index(query[key])) && townships[index] end |
.find_by!(query) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/nayyar/township.rb', line 60 def find_by!(query) if (district = find_by(query)) district else key = get_key(query) raise Nayyar::TownshipNotFound, "Cannot find State with given #{key}: #{query[key]}" end end |
Instance Method Details
#[](key) ⇒ Object
allow the values to be retrieved as an array
30 31 32 33 34 35 36 |
# File 'lib/nayyar/township.rb', line 30 def [](key) if ATTRIBUTES.include? key @data[key] elsif key.to_sym == :district district end end |