Class: Stupidedi::Versions::Common::ElementTypes::AN
- Inherits:
-
SimpleElementDef
- Object
- Schema::AbstractDef
- Schema::AbstractElementDef
- Schema::SimpleElementDef
- SimpleElementDef
- Stupidedi::Versions::Common::ElementTypes::AN
- Defined in:
- lib/stupidedi/versions/common/element_types/an.rb
Direct Known Subclasses
Constant Summary collapse
- DATE_FORMAT_SINGLE =
{"CC" => "%C", #"CD" => "MMMYYYY", # Month and Year Expressed in Format MMMYYYY "CM" => "%Y%m", #"CQ" => "CCYYQ", # Date in Format CCYYQ "CY" => "%Y", "D6" => "%y%m%d", "D8" => "%Y%m%d", "DB" => "%m%d%Y", "DD" => "%d", "DT" => "%Y%m%d%H%M", #"EH" => "YDDD", # Last Digit of Year and Julian Date Expressed in Format YDDD "KA" => "%y%m%d", "MD" => "%m%d", "MM" => "%m", #"TC" => "DDD", # Julian Date Expressed in Format DDD "TM" => "%H%M", "TQ" => "%m%y", "TR" => "%d%m%y%H%M", "TS" => "%H%M%S", "TT" => "%m%d%y", #"TU" => "YYDDD", #"UN" => "", # Unstructured "YM" => "%y%m", "YY" => "%Y", "RTS" => "%Y%m%d%H%M%S"}
- DATE_FORMAT_RANGE =
{"DA" => ["%d", "%d"], "DDT" => ["%Y%m%d", "%Y%m%d%H%M"], "DTD" => ["%Y%m%d%H%M", "%Y%m%d"], "DTS" => ["%Y%m%d%H%M%S", "%Y%m%d%H%M%S"], "RD" => ["%m%d%Y", "%m%d%Y"], "RD2" => ["%y", "%y"], "RD4" => ["%Y", "%Y"], "RD5" => ["%Y%m", "%Y%m"], "RD6" => ["%y%m%d", "%y%m%d"], "RD8" => ["%Y%m%d", "%Y%m%d"], "RDM" => ["%y%m%d", "%m%d"], "RDT" => ["%Y%m%d%H%M", "%Y%m%d%H%M"], "RMD" => ["%m%d", "%m%d"], "RMY" => ["%y%m", "%y%m"], "RTM" => ["%H%M", "%H%M"]}
Instance Attribute Summary
Attributes inherited from SimpleElementDef
#description, #id, #max_length, #min_length, #name, #parent
Attributes inherited from Schema::AbstractElementDef
Class Method Summary collapse
-
.strftime(format, value) ⇒ String
Format date (Date), date time (Time), or a range of either into a String, according to the given format specifier.
-
.strptime(format, value) ⇒ Time | Range<Time>
Parse the string into a date (Date), date time (Time), or a range of either according to the given format specifier.
Instance Method Summary collapse
-
#companion
"YMM" => ["CCYYMMM", "MMM"].
Methods inherited from SimpleElementDef
#copy, #empty, #initialize, #value
Methods inherited from Schema::SimpleElementDef
#code_lists, #component_use, #composite?, #empty, #parent, #parse, #simple?, #simple_use, #value
Methods inherited from Schema::AbstractElementDef
#code_lists, #composite?, #descriptor, #element?, #simple?
Methods included from Inspect
Methods inherited from Schema::AbstractDef
#component?, #composite?, #definition?, #descriptor, #element?, #functional_group?, #interchange?, #loop?, #repeated?, #required?, #segment?, #simple?, #table?, #transaction_set?, #usage?
Constructor Details
This class inherits a constructor from Stupidedi::Versions::Common::ElementTypes::SimpleElementDef
Class Method Details
.strftime(format, value) ⇒ String
Format date (Date), date time (Time), or a range of either into a String, according to the given format specifier.
See DATE_FORMAT_SINGLE and DATE_FORMAT_RANGE for a list of recognized format specifiers.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 77 def strftime(format, value) if AN::DATE_FORMAT_RANGE.defined_at?(format) unless value.kind_of?(Range) and value.end.respond_to?(:strftime) and value.begin.respond_to?(:strftime) raise TypeError, "expected a Range (#strftime..#strftime) but got #{value.inspect}" end f, g = AN::DATE_FORMAT_RANGE.at(format) a, b = value.begin.strftime(f), value.end.strftime(g) "#{a}-#{b}" elsif AN::DATE_FORMAT_SINGLE.defined_at?(format) unless value.respond_to?(:strftime) raise TypeError, "expected value to respond to #strftime, but got #{value.inspect}" end value.strftime(AN::DATE_FORMAT_SINGLE.at(format)) else raise ArgumentError, "unrecognized format specifier #{format.inspect}" end end |
.strptime(format, value) ⇒ Time | Range<Time>
Parse the string into a date (Date), date time (Time), or a range of either according to the given format specifier.
See DATE_FORMAT_SINGLE and DATE_FORMAT_RANGE for a list of recognized format specifiers.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 110 def strptime(format, value) if AN::DATE_FORMAT_RANGE.defined_at?(format) f, g = AN::DATE_FORMAT_RANGE.at(format) a, b = value.split("-", 2) unless value =~ /^[^-]+-[^-]+$/ raise TypeError, "expected a String with format #{f}-#{g}, but got #{value.inspect}" end Time.strptime("#{a} Z", "#{f} %z") .. Time.strptime("#{b} Z", "#{g} %z") elsif AN::DATE_FORMAT_SINGLE.defined_at?(format) Time.strptime("#{value} Z", "#{AN::DATE_FORMAT_SINGLE.at(format)} %z") else raise ArgumentError, "unrecognized format specifier #{format.inspect}" end end |
Instance Method Details
#companion
"YMM" => ["CCYYMMM", "MMM"]
54 55 56 |
# File 'lib/stupidedi/versions/common/element_types/an.rb', line 54 def companion StringVal end |