Class: Suprdate::Unit
- Inherits:
-
Object
- Object
- Suprdate::Unit
- Extended by:
- Comparable, Suprdate::Utility::CleanConstantName
- Includes:
- Comparable
- Defined in:
- lib/suprdate.rb
Overview
Abstract superclass class for Year, Month, Day, etc.
Instance Attribute Summary collapse
-
#value ⇒ Object
(also: #to_i)
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.<=>(opperand) ⇒ Object
Implements Year > Day # => true etc.
-
.significance ⇒ Object
The significance of this unit, in the mathematical sense.
Instance Method Summary collapse
- #==(cmp) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(value) ⇒ Unit
constructor
A new instance of Unit.
-
#new(*args) ⇒ Object
Duplicates this object and reinitialize it.
- #to_s ⇒ Object
Methods included from Suprdate::Utility::CleanConstantName
name_plural, name_singular, to_sym
Constructor Details
#initialize(value) ⇒ Unit
Returns a new instance of Unit.
99 100 101 102 |
# File 'lib/suprdate.rb', line 99 def initialize(value) @value = value self # intentional end |
Instance Attribute Details
#value ⇒ Object (readonly) Also known as: to_i
Returns the value of attribute value.
87 88 89 |
# File 'lib/suprdate.rb', line 87 def value @value end |
Class Method Details
.<=>(opperand) ⇒ Object
Implements Year > Day # => true etc.
121 122 123 124 |
# File 'lib/suprdate.rb', line 121 def self.<=>(opperand) return nil unless opperand.respond_to?(:significance) significance <=> opperand.significance end |
.significance ⇒ Object
The significance of this unit, in the mathematical sense. The significance of a year will be a greater integer than that of a day for instance. The order of elements in UNITs is used to determine this.
110 111 112 113 114 115 116 117 118 |
# File 'lib/suprdate.rb', line 110 def self.significance # I wanted to do this: # UNITS.length - UNITS.index(self) # but it results in an illegal instruction for MRI raise 'Update me' if UNITS.length > 3 return 1 if object_id == Day.object_id return 2 if object_id == Month.object_id 3 end |
Instance Method Details
#==(cmp) ⇒ Object Also known as: eql?
95 |
# File 'lib/suprdate.rb', line 95 def ==(cmp) cmp.class == self.class && (self <=> cmp) == 0 end |
#hash ⇒ Object
97 |
# File 'lib/suprdate.rb', line 97 def hash() inspect.hash end |
#new(*args) ⇒ Object
Duplicates this object and reinitialize it
105 |
# File 'lib/suprdate.rb', line 105 def new(*args) dup.initialize(*args) end |
#to_s ⇒ Object
93 |
# File 'lib/suprdate.rb', line 93 def to_s() inspect end |