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.



116
117
118
# File 'lib/runt/dprecision.rb', line 116

def initialize(prec)
  @precision = prec
end

Instance Attribute Details

#precisionObject (readonly)

Returns the value of attribute precision.



47
48
49
# File 'lib/runt/dprecision.rb', line 47

def precision
  @precision
end

Class Method Details

.dayObject



92
93
94
# File 'lib/runt/dprecision.rb', line 92

def Precision.day
  new(DAY_PREC)
end

.hourObject



96
97
98
# File 'lib/runt/dprecision.rb', line 96

def Precision.hour
  new(HOUR_PREC)
end

.millisecObject



108
109
110
# File 'lib/runt/dprecision.rb', line 108

def Precision.millisec
  new(MILLI_PREC)
end

.minObject



100
101
102
# File 'lib/runt/dprecision.rb', line 100

def Precision.min
  new(MIN_PREC)
end

.monthObject



84
85
86
# File 'lib/runt/dprecision.rb', line 84

def Precision.month
  new(MONTH_PREC)
end

.secObject



104
105
106
# File 'lib/runt/dprecision.rb', line 104

def Precision.sec
  new(SEC_PREC)
end

.weekObject



88
89
90
# File 'lib/runt/dprecision.rb', line 88

def Precision.week
  new(WEEK_PREC)
end

.yearObject



80
81
82
# File 'lib/runt/dprecision.rb', line 80

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

#labelObject



132
133
134
# File 'lib/runt/dprecision.rb', line 132

def label
  LABEL[@precision]
end

#min_valueObject



112
113
114
# File 'lib/runt/dprecision.rb', line 112

def min_value()
  FIELD_MIN[@precision]
end

#to_sObject



128
129
130
# File 'lib/runt/dprecision.rb', line 128

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