Class: FileScheduler::TimeMark
- Includes:
- Comparable
- Defined in:
- lib/file_scheduler/time_mark.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #<=>(time) ⇒ Object
- #[](attribute) ⇒ Object
-
#initialize(attributes = {}) ⇒ TimeMark
constructor
A new instance of TimeMark.
- #matches?(time) ⇒ Boolean
- #to_s ⇒ Object
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
#attributes ⇒ Object (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
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_s ⇒ Object
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 |