Class: Countrizable::ActiveRecord::Attributes

Inherits:
Hash
  • Object
show all
Defined in:
lib/countrizable/active_record/attributes.rb

Overview

TODO: Think about using HashWithIndifferentAccess ?

Instance Method Summary collapse

Instance Method Details

#[](country_code) ⇒ Object



7
8
9
10
11
# File 'lib/countrizable/active_record/attributes.rb', line 7

def [](country_code)
  country_code = country_code.to_sym
  self[country_code] = {} unless has_key?(country_code)
  self.fetch(country_code)
end

#contains?(country_code, name) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/countrizable/active_record/attributes.rb', line 13

def contains?(country_code, name)
  self[country_code].has_key?(name.to_s)
end

#read(country_code, name) ⇒ Object



17
18
19
# File 'lib/countrizable/active_record/attributes.rb', line 17

def read(country_code, name)
  self[country_code][name.to_s]
end

#write(country_code, name, value) ⇒ Object



21
22
23
# File 'lib/countrizable/active_record/attributes.rb', line 21

def write(country_code, name, value)
  self[country_code][name.to_s] = value
end