Class: ONIX::DateStamp
- Inherits:
-
Object
- Object
- ONIX::DateStamp
- Defined in:
- lib/onix/date.rb
Overview
support for datestamp attribute and SentDateTime
Instance Attribute Summary collapse
-
#datetime ⇒ Object
Returns the value of attribute datetime.
-
#format ⇒ Object
Returns the value of attribute format.
Class Method Summary collapse
Instance Method Summary collapse
- #code ⇒ Object
- #human ⇒ Object
-
#initialize(dt = nil, fmt = "%Y%m%d") ⇒ DateStamp
constructor
A new instance of DateStamp.
- #parse(tm) ⇒ Object
- #supported_formats ⇒ Object
Constructor Details
#initialize(dt = nil, fmt = "%Y%m%d") ⇒ DateStamp
Returns a new instance of DateStamp.
96 97 98 99 |
# File 'lib/onix/date.rb', line 96 def initialize(dt = nil, fmt = "%Y%m%d") @datetime = dt @format = fmt unless @datetime.is_a?(String) end |
Instance Attribute Details
#datetime ⇒ Object
Returns the value of attribute datetime.
94 95 96 |
# File 'lib/onix/date.rb', line 94 def datetime @datetime end |
#format ⇒ Object
Returns the value of attribute format.
94 95 96 |
# File 'lib/onix/date.rb', line 94 def format @format end |
Class Method Details
.from_code(code) ⇒ Object
120 121 122 123 124 |
# File 'lib/onix/date.rb', line 120 def self.from_code(code) ds = self.new ds.parse(code) ds end |
Instance Method Details
#code ⇒ Object
130 131 132 |
# File 'lib/onix/date.rb', line 130 def code @format ? @datetime.strftime(@format) : @datetime end |
#human ⇒ Object
126 127 128 |
# File 'lib/onix/date.rb', line 126 def human @datetime end |
#parse(tm) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/onix/date.rb', line 105 def parse(tm) @format = nil found_format = nil supported_formats.each do |supported_format| begin @datetime = Time.strptime(tm, supported_format) found_format = supported_format break rescue end end @format = found_format @datetime = tm unless @format end |
#supported_formats ⇒ Object
101 102 103 |
# File 'lib/onix/date.rb', line 101 def supported_formats ["%Y%m%dT%H%M%S%z", "%Y%m%dT%H%M%S", "%Y%m%dT%H%M%z", "%Y%m%dT%H%M", "%Y%m%d"] end |