Class: Nayyar::State

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/nayyar/state.rb', line 5

def data
  @data
end

Class Method Details

.allObject



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

Instance Method Details

#[](key) ⇒ Object

allow the values to be retrieved as an array



34
35
36
# File 'lib/nayyar/state.rb', line 34

def [](key)
  @data[key]
end

#districtsObject



38
39
40
# File 'lib/nayyar/state.rb', line 38

def districts
  Nayyar::District.of_state self
end