module Card::Director::Stages
Methods for interpreting stages of an action
Constants
- INDECES
- SYMBOLS
Public Instance Methods
finished_stage?(stage)
click to toggle source
# File lib/card/director/stages.rb, line 45 def finished_stage? stage @current_stage_index > stage_index(stage) end
reset_stage()
click to toggle source
# File lib/card/director/stages.rb, line 49 def reset_stage @current_stage_index = -1 end
stage_index(stage)
click to toggle source
# File lib/card/director/stages.rb, line 25 def stage_index stage case stage when Symbol INDECES[stage] when Integer stage when nil -1 else raise Card::Error, "not a valid stage: #{stage}" end end
stage_ok?(opts)
click to toggle source
# File lib/card/director/stages.rb, line 38 def stage_ok? opts return false unless stage test = %i[during before after].find { |t| opts[t] } test ? send("#{test}?", opts[t]) : true end
stage_symbol(index)
click to toggle source
# File lib/card/director/stages.rb, line 15 def stage_symbol index if index.is_a?(Symbol) && INDECES[index] index elsif index.is_a?(Integer) && index < SYMBOLS.size SYMBOLS[index] else raise Card::Error, "not a valid stage index: #{index}" end end
Private Instance Methods
after?(*args)
click to toggle source
# File lib/card/director/stages.rb, line 72 def after? *args stage_test(*args) { |r, t| r < t } end
before?(*args)
click to toggle source
# File lib/card/director/stages.rb, line 64 def before? *args stage_test(*args) { |r, t| r > t } end
during?(*args)
click to toggle source
# File lib/card/director/stages.rb, line 80 def during? *args stage_test(*args) { |r, t| r == t } end
in_or_after?(*args)
click to toggle source
# File lib/card/director/stages.rb, line 76 def in_or_after? *args stage_test(*args) { |r, t| r <= t } end
in_or_before?(*args)
click to toggle source
# File lib/card/director/stages.rb, line 68 def in_or_before? *args stage_test(*args) { |r, t| r >= t } end
previous_stage_index(from_stage=nil)
click to toggle source
# File lib/card/director/stages.rb, line 55 def previous_stage_index from_stage=nil from_stage ||= @current_stage_index stage_index(from_stage) - 1 end
previous_stage_symbol(from_stage=nil)
click to toggle source
# File lib/card/director/stages.rb, line 60 def previous_stage_symbol from_stage=nil stage_symbol previous_stage_index(from_stage) end
stage_test(reference_stage, test_stage=nil) { |stage_index(reference_stage), stage_index(test_stage)| ... }
click to toggle source
# File lib/card/director/stages.rb, line 84 def stage_test reference_stage, test_stage=nil test_stage ||= @current_stage_index yield stage_index(reference_stage), stage_index(test_stage) end