Class: Sapience::Formatters::Base
- Inherits:
-
Object
- Object
- Sapience::Formatters::Base
- Defined in:
- lib/sapience/formatters/base.rb
Instance Attribute Summary collapse
-
#log_application ⇒ Object
Returns the value of attribute log_application.
-
#log_host ⇒ Object
Returns the value of attribute log_host.
-
#precision ⇒ Object
Returns the value of attribute precision.
-
#time_format ⇒ Object
Returns the value of attribute time_format.
Instance Method Summary collapse
-
#format_time(time) ⇒ Object
Return the Time as a formatted string.
-
#initialize(options = {}) ⇒ Base
constructor
Parameters time_format: [String|Symbol|nil] See Time#strftime for the format of this string :iso_8601 Outputs an ISO8601 Formatted timestamp nil: Returns Empty string for time ( no time is output ).
Constructor Details
#initialize(options = {}) ⇒ Base
Parameters
time_format: [String|Symbol|nil]
See Time#strftime for the format of this string
:iso_8601 Outputs an ISO8601 Formatted timestamp
nil: Returns Empty string for time ( no time is output ).
Default: '%Y-%m-%d %H:%M:%S.%6N'
13 14 15 16 17 18 19 20 21 |
# File 'lib/sapience/formatters/base.rb', line 13 def initialize( = {}) = .dup @precision = 6 default_format = "%Y-%m-%d %H:%M:%S.%#{precision}N" @time_format = .key?(:time_format) ? .delete(:time_format) : default_format @log_host = .key?(:log_host) ? .delete(:log_host) : true @log_application = .key?(:log_application) ? .delete(:log_application) : true fail(ArgumentError, "Unknown options: #{.inspect}") unless .empty? end |
Instance Attribute Details
#log_application ⇒ Object
Returns the value of attribute log_application.
5 6 7 |
# File 'lib/sapience/formatters/base.rb', line 5 def log_application @log_application end |
#log_host ⇒ Object
Returns the value of attribute log_host.
5 6 7 |
# File 'lib/sapience/formatters/base.rb', line 5 def log_host @log_host end |
#precision ⇒ Object
Returns the value of attribute precision.
5 6 7 |
# File 'lib/sapience/formatters/base.rb', line 5 def precision @precision end |
#time_format ⇒ Object
Returns the value of attribute time_format.
5 6 7 |
# File 'lib/sapience/formatters/base.rb', line 5 def time_format @time_format end |
Instance Method Details
#format_time(time) ⇒ Object
Return the Time as a formatted string
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sapience/formatters/base.rb', line 24 def format_time(time) case time_format when :iso_8601 time.utc.iso8601(precision) when nil "" else time.strftime(time_format) end end |