class Squib::Args::CardRange
Public Class Methods
new(input, deck_size: 1)
click to toggle source
# File lib/squib/args/card_range.rb, line 10 def initialize(input, deck_size: 1) @range = validate(input, deck_size) end
Public Instance Methods
each(&block)
click to toggle source
Hook into enumerable by delegating to @range
# File lib/squib/args/card_range.rb, line 15 def each(&block) @range.each { |i| block.call(i) } end
size()
click to toggle source
# File lib/squib/args/card_range.rb, line 19 def size @range.size end
Private Instance Methods
validate(input, deck_size)
click to toggle source
# File lib/squib/args/card_range.rb, line 24 def validate(input, deck_size) input ||= :all # default input = 0..(deck_size - 1) if input == :all input = (input.to_i)..(input.to_i) if input.respond_to? :to_i raise ArgumentError.new("#{input} must be Enumerable (i.e. respond_to :each).") unless input.respond_to? :each raise ArgumentError.new("#{input} is outside of deck range of 0..#{deck_size - 1}") if (!input.max.nil?) && (input.max > (deck_size - 1)) input end