Class: Person::Phone

Inherits:
Object
  • Object
show all
Defined in:
lib/poseur/person/phone.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#localeObject

Returns the value of attribute locale.



5
6
7
# File 'lib/poseur/person/phone.rb', line 5

def locale
  @locale
end

#numberObject

Returns the value of attribute number.



3
4
5
# File 'lib/poseur/person/phone.rb', line 3

def number
  @number
end

#typeObject

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_localeObject



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_localeObject



31
32
33
# File 'lib/poseur/person/phone.rb', line 31

def random_area_code_for_locale
  
end

#random_line_from_postal_code_fileObject



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