Sha256: 905c13da654995f86f8fd4b138bf126c57a8f915887afda040cdfc2ba85aeeab

Contents?: true

Size: 851 Bytes

Versions: 9

Compression:

Stored size: 851 Bytes

Contents

require 'semlogr/formatters/property_value_formatter'

module Semlogr
  module Templates
    class PropertyToken
      attr_accessor :property_name

      def initialize(raw_text, property_name)
        @raw_text = raw_text
        @property_name = property_name
      end

      def render(output, properties)
        if properties.key?(@property_name)
          property_value = properties[@property_name]

          Formatters::PropertyValueFormatter.format(output, property_value)
        else
          output << @raw_text
        end
      end

      def ==(other)
        return false unless other
        return false unless other.respond_to?(:property_name)

        @property_name == other.property_name
      end

      def eql?(other)
        self == other
      end

      def hash
        @property_name.hash
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
semlogr-0.3.0 lib/semlogr/templates/property_token.rb
semlogr-0.2.3 lib/semlogr/templates/property_token.rb
semlogr-0.2.2 lib/semlogr/templates/property_token.rb
semlogr-0.2.1 lib/semlogr/templates/property_token.rb
semlogr-0.2.0 lib/semlogr/templates/property_token.rb
semlogr-0.1.3 lib/semlogr/templates/property_token.rb
semlogr-0.1.2 lib/semlogr/templates/property_token.rb
semlogr-0.1.1 lib/semlogr/templates/property_token.rb
semlogr-0.1.0 lib/semlogr/templates/property_token.rb