Class: Stupidedi::Versions::Common::ElementTypes::DateVal

Inherits:
Stupidedi::Values::SimpleElementVal show all
Defined in:
lib/stupidedi/versions/common/element_types/dt.rb

Overview

See Also:

  • B.1.1.3.1.5 Date

Direct Known Subclasses

Invalid, Valid

Defined Under Namespace

Classes: Empty, Improper, Invalid, Proper, Valid

Instance Attribute Summary

Attributes inherited from Stupidedi::Values::SimpleElementVal

#position, #usage

Constructors collapse

Instance Method Summary collapse

Methods inherited from Stupidedi::Values::SimpleElementVal

#allowed?, #component?, #copy, #id?, #initialize, #leaf?, #numeric?, #simple?, #string?, #time?, #to_s, #to_x12, #valid?

Methods inherited from Stupidedi::Values::AbstractElementVal

#element?, #size

Methods inherited from Stupidedi::Values::AbstractVal

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

Methods included from Color

ansi, #ansi

Methods included from Inspect

#inspect

Constructor Details

This class inherits a constructor from Stupidedi::Values::SimpleElementVal

Class Method Details

.empty(usage, position) ⇒ DateVal::Empty

Returns:



509
510
511
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 509

def empty(usage, position)
  self::Empty.new(usage, position)
end

.value(object, usage, position) ⇒ DateVal

Returns:



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 514

def value(object, usage, position)
  if object.is_a?(DateVal)
    object#.copy(:usage => usage, :position => position)
  elsif object.blank?
    self::Empty.new(usage, position)
  elsif object.is_a?(String) or object.is_a?(StringVal)
    string = object.to_s

    if string.length < 6
      self::Invalid.new(object, usage, position)
    else
      day   = string.slice(-2, 2).to_i
      month = string.slice(-4, 2).to_i
      year  = string.slice( 0..-5)

      if year.length < 4
        self::Improper.new(year.to_i, month, day, usage, position)
      else
        self::Proper.new(date(year, month, day), usage, position)
      end
    end
  elsif object.respond_to?(:year) and object.respond_to?(:month) and object.respond_to?(:day)
    self::Proper.new(date(object.year, object.month, object.day), usage, position)
  elsif object.is_a?(Array) and object.length == 3
    if object[0] <= 99
      self::Improper.new(*object, usage, position)
    else
      self::Proper.new(date(*object), usage, position)
    end
  else
    self::Invalid.new(object, usage, position)
  end
rescue Exceptions::InvalidElementError
  self::Invalid.new(object, usage, position)
end

Instance Method Details

#date?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 38

def date?
  true
end

#proper?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 42

def proper?
  false
end

#too_long?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 46

def too_long?
  false
end

#too_short?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 50

def too_short?
  false
end