Class: Semlogr::Templates::PropertyToken

Inherits:
Object
  • Object
show all
Defined in:
lib/semlogr/templates/property_token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_text, property_name, format = nil) ⇒ PropertyToken

Returns a new instance of PropertyToken.



11
12
13
14
15
# 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

Instance Attribute Details

#format_stringObject (readonly)

Returns the value of attribute format_string.



9
10
11
# File 'lib/semlogr/templates/property_token.rb', line 9

def format_string
  @format_string
end

#property_nameObject (readonly)

Returns the value of attribute property_name.



9
10
11
# File 'lib/semlogr/templates/property_token.rb', line 9

def property_name
  @property_name
end

#raw_textObject (readonly)

Returns the value of attribute raw_text.



9
10
11
# File 'lib/semlogr/templates/property_token.rb', line 9

def raw_text
  @raw_text
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# 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) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/semlogr/templates/property_token.rb', line 41

def eql?(other)
  self == other
end

#hashObject



45
46
47
# File 'lib/semlogr/templates/property_token.rb', line 45

def hash
  [raw_text, property_name, format_string].hash
end

#render(output, properties) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# 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