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.
116 117 118 |
# File 'lib/runt/dprecision.rb', line 116 def initialize(prec) @precision = prec end |
Instance Attribute Details
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
47 48 49 |
# File 'lib/runt/dprecision.rb', line 47 def precision @precision end |
Class Method Details
.hour ⇒ Object
96 97 98 |
# File 'lib/runt/dprecision.rb', line 96 def Precision.hour new(HOUR_PREC) end |
.millisec ⇒ Object
108 109 110 |
# File 'lib/runt/dprecision.rb', line 108 def Precision.millisec new(MILLI_PREC) end |
.min ⇒ Object
100 101 102 |
# File 'lib/runt/dprecision.rb', line 100 def Precision.min new(MIN_PREC) end |
.month ⇒ Object
84 85 86 |
# File 'lib/runt/dprecision.rb', line 84 def Precision.month new(MONTH_PREC) end |
.sec ⇒ Object
104 105 106 |
# File 'lib/runt/dprecision.rb', line 104 def Precision.sec new(SEC_PREC) end |
Instance Method Details
#<=>(other) ⇒ Object
120 121 122 |
# File 'lib/runt/dprecision.rb', line 120 def <=>(other) self.precision <=> other.precision end |
#===(other) ⇒ Object
124 125 126 |
# File 'lib/runt/dprecision.rb', line 124 def ===(other) self.precision == other.precision end |
#label ⇒ Object
132 133 134 |
# File 'lib/runt/dprecision.rb', line 132 def label LABEL[@precision] end |
#min_value ⇒ Object
112 113 114 |
# File 'lib/runt/dprecision.rb', line 112 def min_value() FIELD_MIN[@precision] end |
#to_s ⇒ Object
128 129 130 |
# File 'lib/runt/dprecision.rb', line 128 def to_s "DPrecision::#{self.label}" end |