Class: Phoney::Region
- Inherits:
-
Object
- Object
- Phoney::Region
- Defined in:
- lib/phoney/region.rb
Constant Summary collapse
- REGION_FILE =
File.join(File.dirname(__FILE__), '..', 'data', 'regions.bin')
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.
-
#rule_sets ⇒ Object
readonly
Returns the value of attribute rule_sets.
-
#trunk_prefixes ⇒ Object
readonly
Returns the value of attribute trunk_prefixes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Region
constructor
A new instance of Region.
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Region
Returns a new instance of Region.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/phoney/region.rb', line 36 def initialize(={}) @country_abbr = [:country_abbr] @country_code = [:country_code] @trunk_prefixes = [:trunk_prefixes] @dialout_prefixes = [:dialout_prefixes] @rule_sets = SortedSet.new ([:rule_sets]||[]).each do |rule_group| @rule_sets.add RuleGroup.new(rule_group[:significant_digits], rule_group[:rules]) end end |
Instance Attribute Details
#country_abbr ⇒ Object (readonly)
Returns the value of attribute country_abbr.
7 8 9 |
# File 'lib/phoney/region.rb', line 7 def country_abbr @country_abbr end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
7 8 9 |
# File 'lib/phoney/region.rb', line 7 def country_code @country_code end |
#dialout_prefixes ⇒ Object (readonly)
Returns the value of attribute dialout_prefixes.
8 9 10 |
# File 'lib/phoney/region.rb', line 8 def dialout_prefixes @dialout_prefixes end |
#rule_sets ⇒ Object (readonly)
Returns the value of attribute rule_sets.
9 10 11 |
# File 'lib/phoney/region.rb', line 9 def rule_sets @rule_sets end |
#trunk_prefixes ⇒ Object (readonly)
Returns the value of attribute trunk_prefixes.
8 9 10 |
# File 'lib/phoney/region.rb', line 8 def trunk_prefixes @trunk_prefixes end |
Class Method Details
.[](param) ⇒ Object
31 32 33 |
# File 'lib/phoney/region.rb', line 31 def [](param) find(param) end |
.all ⇒ Object
21 22 23 |
# File 'lib/phoney/region.rb', line 21 def all @@regions.empty? ? load : @@regions end |
.find(param) ⇒ Object
25 26 27 28 29 |
# File 'lib/phoney/region.rb', line 25 def find(param) all.detect do |region| region.country_code.to_s == param.to_s || region.country_abbr.to_s == param.to_s end end |
.load ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/phoney/region.rb', line 12 def load @@regions = [] Marshal.load(File.read(REGION_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
50 51 52 |
# File 'lib/phoney/region.rb', line 50 def to_s country_abbr end |