Class: FileScheduler::TimeMark

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/file_scheduler/time_mark.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ TimeMark

Returns a new instance of TimeMark.



21
22
23
# File 'lib/file_scheduler/time_mark.rb', line 21

def initialize(attributes = {})
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



19
20
21
# File 'lib/file_scheduler/time_mark.rb', line 19

def attributes
  @attributes
end

Instance Method Details

#<=>(time) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/file_scheduler/time_mark.rb', line 41

def <=>(time)
  [:year, :month, :day, :week_day, :hour, :minute].each do |attribute|
    value = attributes[attribute]
    if value
      comparaison = value <=> time.send(attribute)
      return comparaison unless comparaison == 0
    end
  end

  0
end

#[](attribute) ⇒ Object



31
32
33
# File 'lib/file_scheduler/time_mark.rb', line 31

def [](attribute)
  attributes[attribute]
end

#matches?(time) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/file_scheduler/time_mark.rb', line 25

def matches?(time)
  attributes.all? do |attribute, value|
    time.send(attribute) == value
  end
end

#to_sObject



55
56
57
58
59
60
61
62
63
# File 'lib/file_scheduler/time_mark.rb', line 55

def to_s
  [:year, :month, :day, :week_day, :hour, :minute].collect do |attribute|
    value = attributes[attribute]
    if value
      suffix = attribute == :month ? "M" : attribute.to_s.chars.first
      "#{value}#{suffix}"
    end
  end.join
end