Class: Eddy::Models::Element::TM
- Defined in:
- lib/eddy/models/element/tm.rb
Overview
Time in HHMMSSDD
format.
Time expressed in 24-hour clock time as follows:
HHMM
, or HHMMSS
, or HHMMSSD
, or HHMMSSDD
where H = hours (00-23), M = minutes (00-59), S = integer seconds (00-59) and DD = decimal seconds;
decimal seconds are expressed as follows:
D = tenths (0-9) and DD = hundredths (00-99)
Values for this type are generated from a UTC formatted Time object.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fmt ⇒ Symbol<:hhmm, :hhmmss, :hhmmssd, :hhmmssdd>
Format for the date.
Attributes inherited from Base
#description, #id, #max, #min, #name, #ref, #type
Class Method Summary collapse
Instance Method Summary collapse
- #accepted_formats ⇒ Array<Symbol>
- #determine_format ⇒ Symbol
-
#initialize(min: nil, max: nil, req: nil, ref: nil, val: nil, fmt: nil) ⇒ void
constructor
TM elements require either a
fmt
value, ormin
andmax
values. - #process_value ⇒ String
- #value ⇒ String
- #value=(arg) ⇒ void
Methods inherited from Base
Constructor Details
#initialize(min: nil, max: nil, req: nil, ref: nil, val: nil, fmt: nil) ⇒ void
TM elements require either a fmt
value, or min
and max
values.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/eddy/models/element/tm.rb', line 33 def initialize( min: nil, max: nil, req: nil, ref: nil, val: nil, fmt: nil ) @type = "TM" @min = min @max = max self.req = req self.ref = ref if fmt.nil? raise ArgumentError, "TM elements require either a `fmt` value, or `min` and `max` values." if min.nil? || max.nil? @fmt = determine_format() else self.fmt = fmt end self.value = val end |
Instance Attribute Details
#fmt ⇒ Symbol<:hhmm, :hhmmss, :hhmmssd, :hhmmssdd>
Format for the date. Valid values: :hhmm
, :hhmmss
, :hhmmssd
, and :hhmmssdd
TODO: Decide if this should be an attr_accessor
21 22 23 |
# File 'lib/eddy/models/element/tm.rb', line 21 def fmt @fmt end |
Class Method Details
.process_value(val, fmt) ⇒ String
86 87 88 89 90 91 92 93 94 |
# File 'lib/eddy/models/element/tm.rb', line 86 def self.process_value(val, fmt) case fmt when :hhmm then return Eddy::Util::Time.hhmm(val) when :hhmmss then return Eddy::Util::Time.hhmmss(val) when :hhmmssd then return Eddy::Util::Time.hhmmssd(val) when :hhmmssdd then return Eddy::Util::Time.hhmmssdd(val) else raise Eddy::Errors::Error, "invalid fmt value for TM object" end end |
Instance Method Details
#accepted_formats ⇒ Array<Symbol>
106 107 108 |
# File 'lib/eddy/models/element/tm.rb', line 106 def accepted_formats() return [:hhmm, :hhmmss, :hhmmssd, :hhmmssdd] end |
#determine_format ⇒ Symbol
111 112 113 114 115 116 117 118 119 |
# File 'lib/eddy/models/element/tm.rb', line 111 def determine_format() case self.max when 4 then return :hhmm when 6 then return :hhmmss when 7 then return :hhmmssd when 8 then return :hhmmssdd else raise Eddy::Errors::Error, "unable to determine format for TM element" end end |
#process_value ⇒ String
79 80 81 |
# File 'lib/eddy/models/element/tm.rb', line 79 def process_value() return self.class.process_value(@val, self.fmt) end |
#value ⇒ String
74 75 76 |
# File 'lib/eddy/models/element/tm.rb', line 74 def value() return super() end |
#value=(arg) ⇒ void
This method returns an undefined value.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/eddy/models/element/tm.rb', line 58 def value=(arg) if arg == :skip @val = :skip return end if arg.nil?() @val = arg return end raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(Time) raise Eddy::Errors::ElementValidationError.new("Argument is not in UTC format", element: self) unless arg.utc?() @val = arg end |