class OodReservations::Reservation

Object that describes a generic scheduler reservation

Attributes

end_time[R]

The time when this reservation ends @return [Time] reservation end time

groups[R]

The list of groups who have access to this reservation @return [Array<OodSupport::Group>] list of groups with reservation access

id[R]

The id of the reservation @return [String] reservation id

nodes[R]

The list of nodes reserved under this reservation @return [Array<Node>] reserved nodes

start_time[R]

The time when this reservation begins @return [Time] reservation start time

users[R]

The list of users who have access to this reservation @return [Array<OodSupport::User>] list of users with reservation access

Public Class Methods

new(id:, start_time:, end_time:, users:, groups:, nodes:) click to toggle source

@param id [#to_s] reservation id @param start_time [#to_i] reservation start time @param end_time [#to_i] reservation end time @param users [Array<#to_s>] list of users w/ reservation access @param groups [Array<#to_s>] list of groups w/ reservation access @param nodes [Array<#to_h>] reserved nodes

# File lib/ood_reservations/reservation.rb, line 38
def initialize(id:, start_time:, end_time:, users:, groups:, nodes:)
  @id         = id.to_s
  @start_time = Time.at(start_time.to_i)
  @end_time   = Time.at(end_time.to_i)
  @nodes      = nodes.map  {|n| Node.new(n.to_h)}

  # Be careful, groups or users can be specified here but not exist anymore
  @users      = users.map  {|u| OodSupport::User.new(u.to_s) rescue nil}.reject(&:nil?)
  @groups     = groups.map {|g| OodSupport::Group.new(g.to_s) rescue nil}.reject(&:nil?)
end

Public Instance Methods

<=>(other) click to toggle source

The comparison operator for sorting values @param other [#to_s] object to compare against @return [Boolean] how objects compare

# File lib/ood_reservations/reservation.rb, line 76
def <=>(other)
  to_s <=> other.to_s
end
eql?(other) click to toggle source

Check whether objects are identical to each other @param other [#to_h] object to compare against @return [Boolean] whether objects are identical

# File lib/ood_reservations/reservation.rb, line 83
def eql?(other)
  self.class == other.class && self == other
end
free_nodes() click to toggle source

The list of nodes that are completely free to use @return [Array<Node>] free nodes

# File lib/ood_reservations/reservation.rb, line 63
def free_nodes
  nodes.select(&:is_free?)
end
has_ended?() click to toggle source

Whether this reservation has ended yet? @return [Boolean] whether reservation has ended

# File lib/ood_reservations/reservation.rb, line 57
def has_ended?
  Time.now >= end_time
end
has_started?() click to toggle source

Whether this reservation has started yet? @return [Boolean] whether reservation has started

# File lib/ood_reservations/reservation.rb, line 51
def has_started?
  Time.now >= start_time
end
hash() click to toggle source

Generate a hash value for this object @return [Fixnum] hash value of object

# File lib/ood_reservations/reservation.rb, line 89
def hash
  [self.class, to_s].hash
end
to_s() click to toggle source

Convert object to string @return [String] the string describing this object

# File lib/ood_reservations/reservation.rb, line 69
def to_s
  id
end