Module: Ruuuby::Feature::Includable::StringF26
- Included in:
- String
- Defined in:
- lib/ruuuby/class/str/str.rb
Overview
defines the operations needed to support Feature(f26) that are applied to Class(String)
Instance Method Summary collapse
-
#as_iso8601 ⇒ String
A normalized representation of iso8601.
-
#iso8601? ⇒ Boolean
True, if the contents of this
Stringare representative of an iso8601 formatted date and/or time. - #to_iso8601 ⇒ DateTime
Instance Method Details
#as_iso8601 ⇒ String
Returns a normalized representation of iso8601.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/ruuuby/class/str/str.rb', line 247 def as_iso8601 🛑 RuntimeError.new("| c{String}-> m{as_iso8601} can't normalize self{#{self}} as it is not similar enough to iso8601 formatted data | (0x0) |") unless self.iso8601? data = self.dup node_date = data[0...10] return self if node_date == self remainder = data[11...data.length] if remainder.length < 8 🛑 RuntimeError.new("| c{String}-> m{as_iso8601} can't normalize self{#{self}} as it is not similar enough to iso8601 formatted data | (0x1) |") else node_time = remainder[0...8] return "#{node_date}T#{node_time}" if node_time == remainder remainder = remainder[8...remainder.length].strip if remainder.match?(::String.syntax_utc_offsets) case(remainder.length) when 3 return "#{node_date}T#{node_time}#{remainder}:00" when 5 return "#{node_date}T#{node_time}#{remainder[0...3]}:#{remainder[3...5]}" when 6 return "#{node_date}T#{node_time}#{remainder}" else 🛑 RuntimeError.new("| c{String}-> m{as_iso8601} can't normalize self{#{self}} as it is not similar enough to iso8601 formatted data | (0x2) |") end else 🛑 RuntimeError.new("| c{String}-> m{as_iso8601} can't normalize self{#{self}} as it is not similar enough to iso8601 formatted data | (0x3) |") end end end |
#iso8601? ⇒ Boolean
Returns true, if the contents of this String are representative of an iso8601 formatted date and/or time.
242 |
# File 'lib/ruuuby/class/str/str.rb', line 242 def iso8601? ; self.length > 3 && self.match?(::String.syntax_iso8601_normalizable) ; end |
#to_iso8601 ⇒ DateTime
279 280 281 282 |
# File 'lib/ruuuby/class/str/str.rb', line 279 def to_iso8601 ::DateTime.iso8601(self.as_iso8601) #DateTime.strptime(self, '%FT%T%:z') end |