Class: Sapience::Formatters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sapience/formatters/base.rb

Direct Known Subclasses

Color, Default

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @precision           = 6
  @default_time_format = "%Y-%m-%d %H:%M:%S.%#{precision}N"
  parse_options(options.dup)
end

Instance Attribute Details

#default_time_formatObject

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_fieldsObject

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_applicationObject

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_hostObject

Returns the value of attribute log_host.



5
6
7
# File 'lib/sapience/formatters/base.rb', line 5

def log_host
  @log_host
end

#precisionObject

Returns the value of attribute precision.



5
6
7
# File 'lib/sapience/formatters/base.rb', line 5

def precision
  @precision
end

#time_formatObject

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