notebook/app/controllers/locations_generator_controller.rb
Robert Richter c032b57318 Refactor GeneratorController
Split it up into three generator controllers.

Also i18n'd all strings
2015-03-27 22:56:45 -05:00

37 lines
837 B
Ruby

# Generates random Location values
class LocationsGeneratorController < ApplicationController
before_action :load_common_fields
def name
@root_name = add_fixes_to base_name
render json: @root_name
end
private
def base_name
@syllables
.sample(rand(@syllables_lower_limit...@syllables_upper_limit))
.join
end
def add_fixes_to(base)
if rand <= @prefix_occurrence
return @prefixes.sample + ' ' + base
elsif rand <= @postfix_occurrence
return base + ' ' + @postfixes.sample
end
end
def load_common_fields
@prefix_occurrence = 0.15
@postfix_occurrence = 0.15
@syllables_upper_limit = 4
@syllables_lower_limit = 2
@prefixes = t(:location_name_prefixes)
@postfixes = t(:location_name_suffixes)
@syllables = t(:location_name_syllables)
end
end