Class: Stupidedi::Versions::Common::ElementTypes::DateVal
Overview
Defined Under Namespace
Classes: Empty, Improper, Invalid, Proper, Valid
Instance Attribute Summary
#position, #usage
Instance Method Summary
collapse
#allowed?, #component?, #copy, #id?, #initialize, #leaf?, #numeric?, #simple?, #string?, #time?, #to_s, #to_x12, #valid?
#element?, #size
#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
Class Method Details
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
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 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
38
39
40
|
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 38
def date?
true
end
|
#proper? ⇒ Boolean
42
43
44
|
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 42
def proper?
false
end
|
#too_long? ⇒ Boolean
46
47
48
|
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 46
def too_long?
false
end
|
#too_short? ⇒ Boolean
50
51
52
|
# File 'lib/stupidedi/versions/common/element_types/dt.rb', line 50
def too_short?
false
end
|