Class: Runt::DPrecision::Precision

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#precisionObject (readonly)

Returns the value of attribute precision.



49
50
51
# File 'lib/runt/dprecision.rb', line 49

def precision
  @precision
end

Class Method Details

.dayObject



94
95
96
# File 'lib/runt/dprecision.rb', line 94

def Precision.day
  new(DAY_PREC)
end

.hourObject



98
99
100
# File 'lib/runt/dprecision.rb', line 98

def Precision.hour
  new(HOUR_PREC)
end

.millisecObject



110
111
112
# File 'lib/runt/dprecision.rb', line 110

def Precision.millisec
  new(MILLI_PREC)
end

.minObject



102
103
104
# File 'lib/runt/dprecision.rb', line 102

def Precision.min
  new(MIN_PREC)
end

.monthObject



86
87
88
# File 'lib/runt/dprecision.rb', line 86

def Precision.month
  new(MONTH_PREC)
end

.secObject



106
107
108
# File 'lib/runt/dprecision.rb', line 106

def Precision.sec
  new(SEC_PREC)
end

.weekObject



90
91
92
# File 'lib/runt/dprecision.rb', line 90

def Precision.week
  new(WEEK_PREC)
end

.yearObject



82
83
84
# File 'lib/runt/dprecision.rb', line 82

def Precision.year
  new(YEAR_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

#labelObject



134
135
136
# File 'lib/runt/dprecision.rb', line 134

def label
  LABEL[@precision]
end

#min_valueObject



114
115
116
# File 'lib/runt/dprecision.rb', line 114

def min_value()
  FIELD_MIN[@precision]
end

#to_sObject



130
131
132
# File 'lib/runt/dprecision.rb', line 130

def to_s
  "DPrecision::#{self.label}"
end