Class: Lumberjack::Formatter::DateTimeFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::DateTimeFormatter
- Defined in:
- lib/lumberjack/formatter/date_time_formatter.rb
Overview
Format a Date, Time, or DateTime object. If you don’t specify a format in the constructor, it will use the ISO-8601 format.
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
- #call(obj) ⇒ Object
-
#initialize(format = nil) ⇒ DateTimeFormatter
constructor
A new instance of DateTimeFormatter.
Constructor Details
#initialize(format = nil) ⇒ DateTimeFormatter
Returns a new instance of DateTimeFormatter.
11 12 13 |
# File 'lib/lumberjack/formatter/date_time_formatter.rb', line 11 def initialize(format = nil) @format = format.dup.to_s.freeze unless format.nil? end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/lumberjack/formatter/date_time_formatter.rb', line 9 def format @format end |
Instance Method Details
#call(obj) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/lumberjack/formatter/date_time_formatter.rb', line 15 def call(obj) if @format && obj.respond_to?(:strftime) obj.strftime(@format) elsif obj.respond_to?(:iso8601) obj.iso8601 else obj.to_s end end |