Class: Availability::Exclusion

Inherits:
InstanceVariableComparability show all
Defined in:
lib/availability/exclusion.rb

Defined Under Namespace

Modules: Rule

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule) ⇒ Exclusion

Returns a new instance of Exclusion.



47
48
49
# File 'lib/availability/exclusion.rb', line 47

def initialize(rule)
  @rule = rule
end

Instance Attribute Details

#ruleObject (readonly)

Returns the value of attribute rule.



3
4
5
# File 'lib/availability/exclusion.rb', line 3

def rule
  @rule
end

Class Method Details

.after_date_and_time(time) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/availability/exclusion.rb', line 10

def self.after_date_and_time(time)
  raise ArgumentError, "invalid time" if time.nil?
  new Rule::AfterDateAndTime.new(time.to_time)
end

.after_day(date) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/availability/exclusion.rb', line 5

def self.after_day(date)
  raise ArgumentError, "invalid date" if date.nil?
  new Rule::AfterDate.new(date.to_date)
end

.after_time(time) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
# File 'lib/availability/exclusion.rb', line 15

def self.after_time(time)
  raise ArgumentError, "invalid time" if time.nil?
  new Rule::AfterTime.new(time.to_time)
end

.all_day(date) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
# File 'lib/availability/exclusion.rb', line 20

def self.all_day(date)
  raise ArgumentError, "invalid date" if date.nil?
  new Rule::OnDate.new(date.to_date)
end

.before_date_and_time(time) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
# File 'lib/availability/exclusion.rb', line 30

def self.before_date_and_time(time)
  raise ArgumentError, "invalid time" if time.nil?
  new Rule::BeforeDateAndTime.new(time.to_time)
end

.before_day(date) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
# File 'lib/availability/exclusion.rb', line 25

def self.before_day(date)
  raise ArgumentError, "invalid date" if date.nil?
  new Rule::BeforeDate.new(date.to_date)
end

.before_time(time) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
# File 'lib/availability/exclusion.rb', line 35

def self.before_time(time)
  raise ArgumentError, "invalid time" if time.nil?
  new Rule::BeforeTime.new(time.to_time)
end

.on_day_of_week(day_of_week) ⇒ Object

0=Sunday, 6=Saturday



40
41
42
43
44
45
# File 'lib/availability/exclusion.rb', line 40

def self.on_day_of_week(day_of_week) # 0=Sunday, 6=Saturday
  unless day_of_week.is_a?(Fixnum) && (0..6).include?(day_of_week)
    raise ArgumentError, "invalid day of week"
  end
  new Rule::OnDayOfWeek.new(day_of_week)
end

Instance Method Details

#<=>(other) ⇒ Object



51
52
53
54
# File 'lib/availability/exclusion.rb', line 51

def <=>(other)
  return 1 if other.nil?
  rule <=> other.rule
end

#violated_by?(time) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/availability/exclusion.rb', line 56

def violated_by?(time)
  @rule.violated_by? time
end