Class: Person::Phone
- Inherits:
-
Object
- Object
- Person::Phone
- Defined in:
- lib/poseur/person/phone.rb
Instance Attribute Summary collapse
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#number ⇒ Object
Returns the value of attribute number.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type = :home, locale = nil) ⇒ Phone
constructor
A new instance of Phone.
- #number_for_locale ⇒ Object
- #random_area_code_for_locale ⇒ Object
- #random_line_from_postal_code_file ⇒ Object
Constructor Details
#initialize(type = :home, locale = nil) ⇒ Phone
Returns a new instance of Phone.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/poseur/person/phone.rb', line 7 def initialize(type=:home, locale=nil) @type = type @locale = locale if locale @locale = locale @number = number_for_locale else @locale, @number = random_locale_and_number end end |
Instance Attribute Details
#locale ⇒ Object
Returns the value of attribute locale.
5 6 7 |
# File 'lib/poseur/person/phone.rb', line 5 def locale @locale end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/poseur/person/phone.rb', line 3 def number @number end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/poseur/person/phone.rb', line 4 def type @type end |
Instance Method Details
#number_for_locale ⇒ Object
18 19 20 |
# File 'lib/poseur/person/phone.rb', line 18 def number_for_locale random_area_code_for_locale.to_s << (1_000_000 + Random.rand(10_000_000 - 1_000_000)).to_s end |
#random_area_code_for_locale ⇒ Object
31 32 33 |
# File 'lib/poseur/person/phone.rb', line 31 def random_area_code_for_locale end |
#random_line_from_postal_code_file ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/poseur/person/phone.rb', line 22 def random_line_from_postal_code_file line = nil File.open("#{ROOT}/locales/postal_codes.usa") do |file| lines = file.readlines line = lines[Random.rand(lines.size)] end line.split(',').collect! { |x| x.strip } end |