Class: Fone::AreaCode

Inherits:
Object
  • Object
show all
Defined in:
lib/fone/area_code.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(area_code, state_abbreviation) ⇒ AreaCode

Returns a new instance of AreaCode.



29
30
31
32
# File 'lib/fone/area_code.rb', line 29

def initialize(area_code, state_abbreviation)
  @to_i = area_code.to_i
  @state_abbreviation = state_abbreviation
end

Instance Attribute Details

#state_abbreviationObject (readonly)

Returns the value of attribute state_abbreviation.



34
35
36
# File 'lib/fone/area_code.rb', line 34

def state_abbreviation
  @state_abbreviation
end

#to_iObject (readonly)

Returns the value of attribute to_i.



34
35
36
# File 'lib/fone/area_code.rb', line 34

def to_i
  @to_i
end

Class Method Details

.[](area_code) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/fone/area_code.rb', line 7

def [](area_code)
  area_code = area_code.to_i
  instances[area_code] || begin
    if datum = data.detect { |a, s| a == area_code }
      instances[area_code] = new *datum
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
# File 'lib/fone/area_code.rb', line 40

def ==(other)
  other.is_a?(AreaCode) && other.to_i == to_i
end

#to_sObject



36
37
38
# File 'lib/fone/area_code.rb', line 36

def to_s
  to_i.to_s
end