Class: Stupidedi::Versions::FunctionalGroups::ThirtyTen::ElementTypes::DateVal::Proper

Inherits:
Stupidedi::Versions::FunctionalGroups::ThirtyTen::ElementTypes::DateVal show all
Extended by:
Operators::Relational, Operators::Unary, Operators::Wrappers
Includes:
Comparable
Defined in:
lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb

Overview

Date with a fully-specified year (with century). Shouldn't be directly instantiated -- instead use the value constructor

Instance Attribute Summary collapse

Attributes inherited from Stupidedi::Values::SimpleElementVal

#position, #usage

Instance Method Summary collapse

Methods included from Operators::Relational

relational_operators

Methods included from Operators::Unary

unary_operators

Methods included from Operators::Wrappers

wrappers

Methods inherited from Stupidedi::Versions::FunctionalGroups::ThirtyTen::ElementTypes::DateVal

#date?, empty, #too_short?, value

Methods inherited from Stupidedi::Values::SimpleElementVal

#allowed?, #component?, #date?, #id?, #leaf?, #numeric?, #simple?, #string?, #time?

Methods inherited from Stupidedi::Values::AbstractElementVal

#element?, #size

Methods inherited from Stupidedi::Values::AbstractVal

#blank?, #characters, #component?, #composite?, #definition, #element?, #functional_group?, #interchange?, #invalid?, #loop?, #present?, #repeated?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?

Methods included from Color

ansi, #ansi

Constructor Details

#initialize(value, usage, position) ⇒ Proper

Returns a new instance of Proper.


193
194
195
196
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 193

def initialize(value, usage, position)
  @value = value
  super(usage, position)
end

Instance Attribute Details

#value (readonly)

Returns the value of attribute value


191
192
193
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 191

def value
  @value
end

Instance Method Details

#coerce(other)


206
207
208
209
210
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 206

def coerce(other)
  # me, he = other.coerce(self)
  # me <OP> he
  return DateVal.value(other, usage, position), self
end

#copy(changes = {}) ⇒ Proper

Returns:


199
200
201
202
203
204
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 199

def copy(changes = {})
  Proper.new \
    changes.fetch(:value, @value),
    changes.fetch(:usage, usage),
    changes.fetch(:position, position)
end

#empty?Boolean

Returns:

  • (Boolean)

216
217
218
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 216

def empty?
  false
end

#futureProper

Returns self.

Returns:


257
258
259
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 257

def future
  self
end

#inspectString

Returns:

  • (String)

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 272

def inspect
  id = definition.bind do |d|
    "[#{"% 5s" % d.id}: #{d.name}]".bind do |s|
      if usage.forbidden?
        ansi.forbidden(s)
      elsif usage.required?
        ansi.required(s)
      else
        ansi.optional(s)
      end
    end
  end

  ansi.element("DT.value#{id}") << "(#{"%04d-%02d-%02d" % [year, month, day]})"
end

#mapDateVal

Returns:


267
268
269
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 267

def map
  DateVal.value(yield(@value), usage, position)
end

#newest(date) ⇒ Proper

Returns self.

Returns:


252
253
254
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 252

def newest(date)
  self
end

#oldest(date) ⇒ Proper

Returns self.

Returns:


247
248
249
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 247

def oldest(date)
  self
end

#pastProper

Returns self.

Returns:


262
263
264
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 262

def past
  self
end

#proper?Boolean

Returns:

  • (Boolean)

220
221
222
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 220

def proper?
  true
end

#to_dateDate

Returns:

  • (Date)

225
226
227
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 225

def to_date
  @value
end

#to_time(hour = nil, minute = nil, second = nil) ⇒ Time

Returns:

  • (Time)

230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 230

def to_time(hour = nil, minute = nil, second = nil)
  if hour.is_a?(TimeVal) and not hour.empty?
    hour, minute, second = hour.hour, hour.minute, hour.second
  end

  if not second.nil?
    Time.utc(year, month, day, hour, minute, second)
  elsif not minute.nil?
    Time.utc(year, month, day, hour, minute)
  elsif not hour.nil?
    Time.utc(year, month, day, hour)
  else
    Time.utc(year, month, day)
  end
end

#to_x12(truncate = true) ⇒ String

Returns:

  • (String)

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 289

def to_x12(truncate = true)
  x12 =
    if definition.max_length < 8
      "%02d%02d%02d" % [year % 100, month, day]
    else
      "%04d%02d%02d" % [year, month, day]
    end

  if truncate    # Drop the most significant digits... they are probably bogus?

    overage = x12.length - definition.max_length
    x12.drop(overage > 0 ? overage : 0)
  else
    x12
  end
end

#too_long?Boolean

Returns:

  • (Boolean)

306
307
308
309
310
311
312
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 306

def too_long?
  if definition.max_length < 8
    definition.max_length - 2 < year.to_s.length
  else
    definition.max_length - 4 < year.to_s.length
  end
end

#valid?Boolean

Returns:

  • (Boolean)

212
213
214
# File 'lib/stupidedi/versions/functional_groups/003010/element_types/date_val.rb', line 212

def valid?
  true
end