Class: RandomPerson::Names::AmericanPrefix
- Inherits:
-
RandomPerson::Name
- Object
- RandomPerson::Name
- RandomPerson::Names::AmericanPrefix
- Defined in:
- lib/randomperson/Names/AmericanPrefix.rb
Instance Attribute Summary
Attributes inherited from RandomPerson::Name
#formats, #formats_ratiod, #names
Instance Method Summary collapse
- #execute(person) ⇒ Object
-
#initialize ⇒ AmericanPrefix
constructor
A new instance of AmericanPrefix.
Constructor Details
#initialize ⇒ AmericanPrefix
Returns a new instance of AmericanPrefix.
6 7 8 9 10 11 |
# File 'lib/randomperson/Names/AmericanPrefix.rb', line 6 def initialize @formats_ratiod = [ 0..47, 48..49, 50..69, 70..87, 88..99] @names = %w(Mr. Dr. Mrs. Ms. Miss ) end |
Instance Method Details
#execute(person) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/randomperson/Names/AmericanPrefix.rb', line 13 def execute( person ) if person.age < 17 return 'Miss' if person.gender == 'f' return 'Mr.' end r = rand(100) #0..99 i = @formats_ratiod.index_in_range( r ) return @names[i] end |