Sha256: 2409c2b0800b41d659e3bd2a0113eecf36a30ec87f75cd886f5ceab6641086dc
Contents?: true
Size: 721 Bytes
Versions: 2
Compression:
Stored size: 721 Bytes
Contents
# frozen_string_literal: true module CodebrekerManfly class CodeGenerator < ValidatableEntity DEFAULT_CODE_RANGE = (1..6).freeze DEFAULT_CODE_LENGTH = 4 def initialize(range: DEFAULT_CODE_RANGE, amount: DEFAULT_CODE_LENGTH) super() @range = range @amount = amount end def generate Array.new(@amount) { rand(@range) } end private def validate add_error(:range, I18n.t(:unexpected_class_error)) unless valid_class?(Range, @range) return add_error(:amount, I18n.t(:unexpected_class_error)) unless valid_class?(Integer, @amount) add_error(:amount, I18n.t(:non_positive_integer_error)) unless valid_positive_integer?(@amount) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
codebreker_manfly-0.1.2 | lib/codebreker_manfly/entities/code_generator.rb |
codebreker_manfly-0.1.1 | lib/codebreker_manfly/entities/code_generator.rb |