Sha256: c3eafe6adeeddaa16193e32afcf5bf5e5fe649629ba8f199ce4b9add9a28bf16

Contents?: true

Size: 682 Bytes

Versions: 1

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

require 'time'

require_relative 'monkey_action'
require_relative 'monkey_timed_action'
require 'MonkeyEngine/exceptions'

# Monkey action:  eat (as in banana)
# The monkey is eating.
class MonkeyActionEat < MonkeyTimedAction
  WEIGHT = 2.0
  VALID_VALUES = (30..60) # 30 through 60 minutes

  def initialize(monkey, value)
    super monkey, value, WEIGHT

    @action_time_of_completion = @action_time + (value * 60)

    validate

    self
  end

  protected

  def validate
    super

    raise MonkeyEngine::Exceptions::InvalidArgumentValueException, "Value '#{value}' is not a valid value"  \
      unless VALID_VALUES.include?(@value)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
MonkeyEngine-2.0.0 lib/MonkeyAction/monkey_action_eat.rb