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:

  • B.1.1.3.1.5 Date

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

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



508
509
510
# File 'lib/stupidedi/versions/functional_groups/005010/element_types/date_val.rb', line 508

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

.value(object, usage, position) ⇒ DateVal



513
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/functional_groups/005010/element_types/date_val.rb', line 513

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

#date?Boolean



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

def date?
  true
end

#too_long?Boolean



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

def too_long?
  false
end

#too_short?Boolean



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

def too_short?
  false
end