Class: Stupidedi::Versions::FunctionalGroups::FiftyTen::ElementTypes::DateVal

Inherits:
Stupidedi::Values::SimpleElementVal show all
Defined in:
lib/stupidedi/versions/functional_groups/005010/element_types/date_val.rb

Overview

See Also:

Direct Known Subclasses

Empty, Improper, Invalid, Proper

Defined Under Namespace

Classes: Empty, Improper, Invalid, Proper

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_x12

Methods inherited from Stupidedi::Values::AbstractElementVal

#element?, #size

Methods inherited from Stupidedi::Values::AbstractVal

#blank?, #characters, #component?, #composite?, #definition, #element?, #empty?, #functional_group?, #interchange?, #invalid?, #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

+ (DateVal::Empty) empty(usage, position)



512
513
514
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/date_val.rb', line 512

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

+ (DateVal) value(object, usage, position)



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
549
550
551
552
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/date_val.rb', line 517

def value(object, usage, position)
  if 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
        date = date(year, month, day)
        self::Proper.new(date, usage, position)
      end
    end

  elsif object.respond_to?(:year) and object.respond_to?(:month) and object.respond_to?(:day)
    date = date(object.year, object.month, object.day)
    self::Proper.new(date, usage, position)

  elsif object.is_a?(DateVal::Improper)
    self::Improper.new(object.year, object.month, object.day, usage, position)

  else
    self::Invalid.new(object, usage, position)
  end

rescue Exceptions::InvalidElementError
  self::Invalid.new(object, usage, position)
end

Instance Method Details

- (Boolean) date?



38
39
40
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/date_val.rb', line 38

def date?
  true
end

- (Boolean) too_long?



42
43
44
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/date_val.rb', line 42

def too_long?
  false
end

- (Boolean) too_short?



46
47
48
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/date_val.rb', line 46

def too_short?
  false
end