Sha256: 1261cb67a8492eaa94837c7c4eb95ebf80a337fe9e2011b6c03431569823c971

Contents?: true

Size: 890 Bytes

Versions: 22

Compression:

Stored size: 890 Bytes

Contents

module Kuroko2
  module Workflow
    module Task
      class TimeBase < Base
        class << self
          attr_reader :task_name

          def set_task_name(task_name)
            @task_name = task_name
          end
        end

        def execute
          if option.present?
            validate
            token.context[self.class.task_name] = to_minutes(option)
          end

          :next
        end

        def validate
          unless /\A\d+(?:h|m)?\z/ === option
            raise Workflow::AssertionError,
              "A value of #{self.class.task_name} should be a number."
          end
        end

        private

        def to_minutes(option)
          case option
          when /\A(\d+)h\z/
            $1.to_i * 60
          when /\A(\d+)m\z/
            $1.to_i
          else
            option.to_i
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
kuroko2-0.8.0 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.7.0 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.6.0 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.5.2 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.5.1 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.5.0 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.4.6 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.4.5 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.4.4 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.4.3 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.4.2 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.4.1 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.4.0 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.3.4 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.3.3 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.3.2 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.3.1 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.3.0 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.2.3 lib/autoload/kuroko2/workflow/task/time_base.rb
kuroko2-0.2.2 lib/autoload/kuroko2/workflow/task/time_base.rb