class CW::Callsign
Public Instance Methods
*(number)
click to toggle source
# File lib/cw/callsign.rb, line 50 def * number calls = [] number.times do calls << construct end calls end
callsigns()
click to toggle source
# File lib/cw/callsign.rb, line 6 def callsigns if @callsigns.nil? @callsigns = load_callsigns end @callsigns end
construct()
click to toggle source
# File lib/cw/callsign.rb, line 42 def construct call = '' 0.upto(4) do |count| call << select_part(partial_name(count)) end call.strip end
load_callsigns()
click to toggle source
# File lib/cw/callsign.rb, line 13 def load_callsigns File.open(CALLS_FILENAME, "r") do |calls| YAML::load(calls) end end
partial_name(count)
click to toggle source
# File lib/cw/callsign.rb, line 38 def partial_name count "partial_#{count}".to_sym end
rand_val()
click to toggle source
# File lib/cw/callsign.rb, line 20 def rand_val rand(100) end
select_part(country = :uk, partial)
click to toggle source
# File lib/cw/callsign.rb, line 24 def select_part country = :uk, partial pc = rand_val weight = callsigns[country][partial][:weight] tot_wt = 0 weight.each_with_index do |wt, idx| tot_wt += wt if pc < tot_wt part = callsigns[country][partial][:option][idx] return part unless(part.class == Range) return part.to_a.sample end end end