class Semlogr::Templates::PropertyToken

Attributes

format_string[R]
property_name[R]
raw_text[R]

Public Class Methods

new(raw_text, property_name, format = nil) click to toggle source
# File lib/semlogr/templates/property_token.rb, line 11
def initialize(raw_text, property_name, format = nil)
  @raw_text = raw_text
  @property_name = property_name
  @format_string = format ? "%#{format}" : nil
end

Public Instance Methods

==(other) click to toggle source
# File lib/semlogr/templates/property_token.rb, line 30
def ==(other)
  return false unless other
  return false unless other.respond_to?(:raw_text)
  return false unless other.respond_to?(:property_name)
  return false unless other.respond_to?(:format_string)

  raw_text == other.raw_text && \
    property_name == other.property_name && \
    format_string == other.format_string
end
eql?(other) click to toggle source
# File lib/semlogr/templates/property_token.rb, line 41
def eql?(other)
  self == other
end
hash() click to toggle source
# File lib/semlogr/templates/property_token.rb, line 45
def hash
  [raw_text, property_name, format_string].hash
end
render(output, properties) click to toggle source
# File lib/semlogr/templates/property_token.rb, line 17
def render(output, properties)
  output <<
    if properties.key?(property_name)
      format_property_value(properties[property_name])
    else
      raw_text
    end
rescue StandardError => e
  SelfLogger.error("Failed to render property token: #{property_name}", e)

  output << raw_text
end

Private Instance Methods

format_property_value(property_value) click to toggle source
# File lib/semlogr/templates/property_token.rb, line 51
def format_property_value(property_value)
  if format_string
    format(format_string, property_value)
  else
    Formatters::PropertyValueFormatter.format(property_value)
  end
end