class Elevatore::Person
Attributes
enter_at[R]
exit_at[RW]
from[R]
id[R]
pickup_at[RW]
to[R]
Public Class Methods
new(opts={})
click to toggle source
# File lib/elevatore/person.rb, line 5 def initialize opts={} enforce_rules! opts @id = opts["id"] @from = opts["from"] @to = opts["to"] @enter_at = opts["enter_at"] end
Private Instance Methods
enforce_rules!(opts)
click to toggle source
# File lib/elevatore/person.rb, line 14 def enforce_rules! opts if (opts["enter_at"].to_f%Elevatore::SPEED).round != 0 raise ArgumentError.new("Error on P#{opts["id"]}: Time should grow in multiples of #{Elevatore::SPEED}") end if opts["enter_at"].to_f < 0 raise ArgumentError.new("Error on P#{opts["id"]}: Time starts at 0") end round_numbers=[opts["id"], opts["from"], opts["to"]] if round_numbers.any?{|int| int.class <= Float } raise ArgumentError.new("Error on P#{opts["id"]}: Only time can be fractioned") end route=[opts["from"], opts["to"]] if route.max > Elevatore::TOP_LEVEL || route.min < Elevatore::LOWER_LEVEL raise ArgumentError.new("Error on P#{opts["id"]}: Floors should be between #{Elevatore::LOWER_LEVEL} and #{Elevatore::TOP_LEVEL}") end end