Class: RubbishCollection::Resolution
- Inherits:
-
Object
- Object
- RubbishCollection::Resolution
- Includes:
- Comparable
- Defined in:
- lib/rubbish_collection.rb
Constant Summary collapse
- SECOND =
new "Second", 1
- MINUTE =
new "Minute", 60
- HOUR =
new "Hour", 3600
- DAY =
new "Day", 86400
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(name, step) ⇒ Resolution
constructor
A new instance of Resolution.
- #match_resolution(time) ⇒ Object
Constructor Details
#initialize(name, step) ⇒ Resolution
Returns a new instance of Resolution.
53 54 55 56 |
# File 'lib/rubbish_collection.rb', line 53 def initialize name, step self.name = name self.step = step end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
47 48 49 |
# File 'lib/rubbish_collection.rb', line 47 def name @name end |
#step ⇒ Object
Returns the value of attribute step.
50 51 52 |
# File 'lib/rubbish_collection.rb', line 50 def step @step end |
Instance Method Details
#<=>(other) ⇒ Object
58 59 60 |
# File 'lib/rubbish_collection.rb', line 58 def <=> other other.step <=> step end |
#match_resolution(time) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rubbish_collection.rb', line 63 def match_resolution time args = [ time.year, time.month, time.day, time.hour, time.min, time.sec, time.usec ] case step when 1 Runt::PDate.sec *args when 60 Runt::PDate.min *args when 3600 Runt::PDate.hour *args when 86400 Runt::PDate.day *args else raise "Don't know how to represent a time with resolution of #{step}" end end |