class Pinpoint::Format::Style

Attributes

structure[RW]

Protected: Access to the underlying structure of the Style (typically is a result of calling Pinpoint::Format::Parser#parse.

Public Class Methods

from_yaml(style_definition) click to toggle source

Public: Processes the style information gleaned from the Pinpoint YAML format and generates a Style from it.

style - The style information from the Pinpoint YAML format file. For

example:

    (%s, )(%l, )(%p )%z(, %c)

Returns a Pinpoint::Format::Style based on the information passed in.

# File lib/pinpoint/format/style.rb, line 18
def self.from_yaml(style_definition)
  style = new
  style.send(:structure=, Format::Parser.new(style_definition).parse)
  style
end

Public Instance Methods

output(address) click to toggle source

Public: Can take an address-like object and output it in the style specified by the structure.

Example

# Assuming address is an address-like object and Style was
# instantiated with '(%s, )(%l, )(%p )%z(, %c)'
output address
# => '123 First Street, Nashville, TN 37033, United States'
# File lib/pinpoint/format/style.rb, line 35
def output(address)
  process(structure, address)
end

Private Instance Methods

no_alphanumerics() click to toggle source
# File lib/pinpoint/format/style.rb, line 75
def no_alphanumerics
  /\A[^A-Za-z0-9]*\z/
end
process(structure, context) click to toggle source

Private: Can take a Style structure and assemble a String from data from a context.

When finishing with a grouping, if there is no alphanumeric content within a grouping, it will be discarded.

Returns a String containing data from the context and String literals

# File lib/pinpoint/format/style.rb, line 58
def process(structure, context)
  processed = ''.html_safe

  structure.each_with_object(processed) do |token, result|
    result << case token
              when Array
                process(token, context)
              when Symbol
                context.public_send(token)
              when String
                token.html_safe
              end
  end

  processed.match(no_alphanumerics) ? ''.html_safe : processed
end