Class: PhoneNumber::Region
- Inherits:
-
Object
- Object
- PhoneNumber::Region
- Defined in:
- lib/phoney/region.rb
Constant Summary collapse
- @@regions =
[]
Instance Attribute Summary collapse
-
#country_abbr ⇒ Object
readonly
Returns the value of attribute country_abbr.
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#dialout_prefixes ⇒ Object
readonly
Returns the value of attribute dialout_prefixes.
-
#national_prefix ⇒ Object
readonly
Returns the value of attribute national_prefix.
-
#rule_sets ⇒ Object
readonly
Returns the value of attribute rule_sets.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Region
constructor
A new instance of Region.
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ Region
Returns a new instance of Region.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/phoney/region.rb', line 45 def initialize(hash) @country_abbr = hash[:country_abbr] @country_code = hash[:country_code] @national_prefix = hash[:national_prefix] @dialout_prefixes = hash[:dialout_prefixes] @rule_sets = hash[:rule_sets] if(@rule_sets) for rule_set in @rule_sets do if(rule_set[:rules]) rule_set[:rules].each_with_index do |rule,index| rule.merge!(:index => index) end end end end end |
Instance Attribute Details
#country_abbr ⇒ Object (readonly)
Returns the value of attribute country_abbr.
8 9 10 |
# File 'lib/phoney/region.rb', line 8 def country_abbr @country_abbr end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
8 9 10 |
# File 'lib/phoney/region.rb', line 8 def country_code @country_code end |
#dialout_prefixes ⇒ Object (readonly)
Returns the value of attribute dialout_prefixes.
9 10 11 |
# File 'lib/phoney/region.rb', line 9 def dialout_prefixes @dialout_prefixes end |
#national_prefix ⇒ Object (readonly)
Returns the value of attribute national_prefix.
9 10 11 |
# File 'lib/phoney/region.rb', line 9 def national_prefix @national_prefix end |
#rule_sets ⇒ Object (readonly)
Returns the value of attribute rule_sets.
10 11 12 |
# File 'lib/phoney/region.rb', line 10 def rule_sets @rule_sets end |
Class Method Details
.[](param) ⇒ Object
40 41 42 |
# File 'lib/phoney/region.rb', line 40 def [](param) find(param) end |
.all ⇒ Object
24 25 26 27 28 |
# File 'lib/phoney/region.rb', line 24 def all return @@regions unless @@regions.empty? load end |
.find(param) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/phoney/region.rb', line 30 def find(param) return nil unless param param = param.to_sym all.detect do |region| region.country_code == param || region.country_abbr == param end end |
.load ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/phoney/region.rb', line 13 def load data_file = File.join(File.dirname(__FILE__), '..', 'data', 'regions.yml') @@regions = [] YAML.load(File.read(data_file)).each_pair do |key, region_hash| new_region = Region.new(region_hash) @@regions.push(new_region) end @@regions end |
Instance Method Details
#to_s ⇒ Object
65 66 67 |
# File 'lib/phoney/region.rb', line 65 def to_s "#{@country_abbr.to_s} [+#{@country_code.to_s}]" end |