class Kodo::Generator
Constants
- DEFAULT_ALGORITHM
Attributes
algorithm[R]
count[R]
max_length[R]
Public Class Methods
new(options=nil)
click to toggle source
# File lib/kodo/core/generator.rb, line 7 def initialize(options=nil) self.algorithm = options.algorithm self.count = options.count self.max_length = options.max_length end
Public Instance Methods
algorithm=(type=nil)
click to toggle source
# File lib/kodo/core/generator.rb, line 27 def algorithm=(type=nil) if type.nil? self.algorithm = DEFAULT_ALGORITHM else begin if !Object.const_defined?("Kodo::Algorithms::#{type.capitalize}") raise Kodo::AlgorithmNotFound, "\"#{type}\" is not a valid algorithm." end algorithm = Object.const_get("Kodo::Algorithms::#{type.capitalize}") rescue Exception => e raise e, "Failed to reference algorithm \"#{type.capitalize}\" - #{e.message}" end @algorithm = algorithm end end
count=(number=1)
click to toggle source
# File lib/kodo/core/generator.rb, line 45 def count=(number=1) if number.nil? number = 1 end @count = number.to_i end
max_length=(size=nil)
click to toggle source
# File lib/kodo/core/generator.rb, line 13 def max_length=(size=nil) if !size.nil? if @algorithm != Kodo::Algorithms::Random raise Kodo::InvalidArgumentCombination, "Max length cannot be used for the #{@algorithm.name} algorithm" end if size.to_i >= 1 && size.to_i <= 512 @max_length = size.to_i else raise Exception, 'Max length must be greater than 1 and less than 512' end end end
run()
click to toggle source
# File lib/kodo/core/generator.rb, line 53 def run algorithm = @algorithm.new(@count, @max_length) algorithm.create end