Class: Eddy::Models::Element::TM

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

Elements::E337, Elements::I09

Instance Attribute Summary collapse

Attributes inherited from Base

#description, #id, #max, #min, #name, #ref, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#doc_comment, #req, #req=

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.

Parameters:

  • min (Integer) (defaults to: nil)

    (nil)

  • max (Integer) (defaults to: nil)

    (nil)

  • req (String) (defaults to: nil)

    (nil)

  • ref (String) (defaults to: nil)

    (nil)

  • val (Time) (defaults to: nil)

    (nil)

  • fmt (Symbol) (defaults to: nil)

    (nil) Format for the date. Valid values: :hhmm, :hhmmss, :hhmmssd, and :hhmmssdd

Raises:

  • (ArgumentError)

    If an invalid format argument is passed.



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

#fmtSymbol<:hhmm, :hhmmss, :hhmmssd, :hhmmssdd>

Format for the date. Valid values: :hhmm, :hhmmss, :hhmmssd, and :hhmmssdd TODO: Decide if this should be an attr_accessor

Returns:

  • (Symbol<:hhmm, :hhmmss, :hhmmssd, :hhmmssdd>)


21
22
23
# File 'lib/eddy/models/element/tm.rb', line 21

def fmt
  @fmt
end

Class Method Details

.process_value(val, fmt) ⇒ String

Parameters:

  • val (Time)

    A UTC formatted Time object.

  • fmt (Symbol)

Returns:

  • (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_formatsArray<Symbol>

Returns:

  • (Array<Symbol>)


106
107
108
# File 'lib/eddy/models/element/tm.rb', line 106

def accepted_formats()
  return [:hhmm, :hhmmss, :hhmmssd, :hhmmssdd]
end

#determine_formatSymbol

Returns:

  • (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_valueString

Returns:

  • (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

#valueString

Returns:

  • (String)

Raises:



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.

Parameters:

  • arg (Time)

    A UTC formatted Time object.

Raises:

  • (ElementValidationError)

    Unless passed a UTC formatted Time object.



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