lib/egn/generator.rb in egn-1.1.0 vs lib/egn/generator.rb in egn-1.2.0
- old
+ new
@@ -30,34 +30,35 @@
# Check if the options contain a date that is valid and be turned into an EGN
def validate!(options)
raise ArgumentError, "Year out of bounds" unless (1800..2099).include?(options[:year])
raise ArgumentError, "Month out of bounds" unless (1..12).include?(options[:month])
raise ArgumentError, "Day out of bounds" unless (1..31).include?(options[:day])
+ raise ArgumentError, "Invalid sex; valid values: [:male, :female]" unless [:male, :female].include?(options[:sex])
end
def defaults
date = Util.time_rand
{
year: date.year,
month: date.month,
- day: date.day
+ day: date.day,
+ sex: [:male, :female].sample
}
end
def randomize_options
# Get random century, region and sex
options[:century] = options[:year] - (options[:year] % 100)
options[:region] = Random.rand(0..999)
- options[:sex] = Random.rand(1..2)
# Recalculate month based on the century
options[:month] += 20 if options[:century] == 1800
options[:month] += 40 if options[:century] == 2000
# Recalculate region based on sex
- if options[:sex] == 1 && options[:region].odd?
+ if options[:sex] == :male && options[:region].odd?
options[:region] -= 1
- elsif options[:sex] == 2 && options[:region].even?
+ elsif options[:sex] == :female && options[:region].even?
options[:region] += 1
end
options[:year] = options[:year] - options[:century]
end