Class: Sapience::Formatters::Base
- Inherits:
-
Object
- Object
- Sapience::Formatters::Base
- Defined in:
- lib/sapience/formatters/base.rb
Instance Attribute Summary collapse
-
#default_time_format ⇒ Object
Returns the value of attribute default_time_format.
-
#exclude_fields ⇒ Object
Returns the value of attribute exclude_fields.
-
#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 |
# File 'lib/sapience/formatters/base.rb', line 13 def initialize( = {}) @precision = 6 @default_time_format = "%Y-%m-%d %H:%M:%S.%#{precision}N" (.dup) end |
Instance Attribute Details
#default_time_format ⇒ Object
Returns the value of attribute default_time_format.
5 6 7 |
# File 'lib/sapience/formatters/base.rb', line 5 def default_time_format @default_time_format end |
#exclude_fields ⇒ Object
Returns the value of attribute exclude_fields.
5 6 7 |
# File 'lib/sapience/formatters/base.rb', line 5 def exclude_fields @exclude_fields end |
#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
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sapience/formatters/base.rb', line 20 def format_time(time) case time_format when :iso_8601 time.utc.iso8601(precision) when nil "" else time.strftime(time_format) end end |