Class: Nayyar::State
- Inherits:
-
Object
- Object
- Nayyar::State
- Defined in:
- lib/nayyar/state.rb
Overview
Represents a State in Myanmar
Constant Summary collapse
- ATTRIBUTES =
%i[ pcode iso alpha3 name my_name ].freeze
- INDICES =
%w[pcode iso alpha3].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.
- #districts ⇒ Object
-
#initialize(data) ⇒ State
constructor
A new instance of State.
Constructor Details
#initialize(data) ⇒ State
Returns a new instance of State.
22 23 24 |
# File 'lib/nayyar/state.rb', line 22 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/nayyar/state.rb', line 5 def data @data end |
Class Method Details
.all ⇒ Object
43 44 45 |
# File 'lib/nayyar/state.rb', line 43 def all states end |
.find_by(query) ⇒ Object
47 48 49 50 |
# File 'lib/nayyar/state.rb', line 47 def find_by(query) key = get_key(query) (index = send("#{key}_index".to_sym).index(query[key])) && states[index] end |
.find_by!(query) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/nayyar/state.rb', line 52 def find_by!(query) if (state = find_by(query)) state else key = get_key(query) raise Nayyar::StateNotFound, "Cannot find State with given #{key}: #{query[key]}" end end |