Class: Runt::DPrecision::Precision
- Inherits:
-
Object
- Object
- Runt::DPrecision::Precision
- Includes:
- Comparable
- Defined in:
- lib/runt/dprecision.rb
Overview
Simple value class for keeping track of precisioned dates
Constant Summary collapse
- YEAR_PREC =
Some constants w/arbitrary integer values used internally for comparisions
0
- MONTH_PREC =
1
- WEEK_PREC =
2
- DAY_PREC =
3
- HOUR_PREC =
4
- MIN_PREC =
5
- SEC_PREC =
6
- MILLI_PREC =
7
- LABEL =
String values for display
{ YEAR_PREC => "YEAR", MONTH_PREC => "MONTH", WEEK_PREC => "WEEK", DAY_PREC => "DAY", HOUR_PREC => "HOUR", MIN_PREC => "MINUTE", SEC_PREC => "SECOND", MILLI_PREC => "MILLISECOND"}
- FIELD_MIN =
Minimun values that precisioned fields get set to
{ YEAR_PREC => 1, MONTH_PREC => 1, WEEK_PREC => 1, DAY_PREC => 1, HOUR_PREC => 0, MIN_PREC => 0, SEC_PREC => 0, MILLI_PREC => 0}
Instance Attribute Summary collapse
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
Class Method Summary collapse
- .day ⇒ Object
- .hour ⇒ Object
- .millisec ⇒ Object
- .min ⇒ Object
- .month ⇒ Object
- .sec ⇒ Object
- .week ⇒ Object
- .year ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #===(other) ⇒ Object
-
#initialize(prec) ⇒ Precision
constructor
A new instance of Precision.
- #label ⇒ Object
- #min_value ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(prec) ⇒ Precision
Returns a new instance of Precision.
118 119 120 |
# File 'lib/runt/dprecision.rb', line 118 def initialize(prec) @precision = prec end |
Instance Attribute Details
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
49 50 51 |
# File 'lib/runt/dprecision.rb', line 49 def precision @precision end |
Class Method Details
.hour ⇒ Object
98 99 100 |
# File 'lib/runt/dprecision.rb', line 98 def Precision.hour new(HOUR_PREC) end |
.millisec ⇒ Object
110 111 112 |
# File 'lib/runt/dprecision.rb', line 110 def Precision.millisec new(MILLI_PREC) end |
.min ⇒ Object
102 103 104 |
# File 'lib/runt/dprecision.rb', line 102 def Precision.min new(MIN_PREC) end |
.month ⇒ Object
86 87 88 |
# File 'lib/runt/dprecision.rb', line 86 def Precision.month new(MONTH_PREC) end |
.sec ⇒ Object
106 107 108 |
# File 'lib/runt/dprecision.rb', line 106 def Precision.sec new(SEC_PREC) end |
Instance Method Details
#<=>(other) ⇒ Object
122 123 124 |
# File 'lib/runt/dprecision.rb', line 122 def <=>(other) self.precision <=> other.precision end |
#===(other) ⇒ Object
126 127 128 |
# File 'lib/runt/dprecision.rb', line 126 def ===(other) self.precision == other.precision end |
#label ⇒ Object
134 135 136 |
# File 'lib/runt/dprecision.rb', line 134 def label LABEL[@precision] end |
#min_value ⇒ Object
114 115 116 |
# File 'lib/runt/dprecision.rb', line 114 def min_value() FIELD_MIN[@precision] end |
#to_s ⇒ Object
130 131 132 |
# File 'lib/runt/dprecision.rb', line 130 def to_s "DPrecision::#{self.label}" end |