class PostRunner::Schema

A Schema provides a unified way to query and process diverse data types.

Attributes

column_alignment[R]
func[R]
imperial_unit[R]
key[R]
metric_unit[R]
name[R]

Public Class Methods

new(key, name, opts = {}) click to toggle source

Create a Schema object. @param key [Symbol] The globally unique identifier for the object @param name [String] A human readable name to describe the object @param opts [Hash] A Hash with values to overwrite the default values

of some instance variables.
# File lib/postrunner/Schema.rb, line 26
def initialize(key, name, opts = {})
  @key = key
  @name = name

  # Default values for optional variables
  @func = nil
  @format = nil
  @column_alignment = :right
  @metric_unit = nil
  @imperial_unit = nil

  # Overwrite the default value for optional variables that have values
  # provided in opts.
  opts.each do |on, ov|
    if instance_variable_defined?('@' + on.to_s)
      instance_variable_set('@' + on.to_s, ov)
    else
      raise ArgumentError, "Unknown instance variable '#{on}'"
    end
  end
end

Public Instance Methods

to_s(value) click to toggle source
# File lib/postrunner/Schema.rb, line 48
def to_s(value)
  value = send(@format, value) if @format
  value.to_s
end

Private Instance Methods

date_with_weekday(timestamp) click to toggle source
# File lib/postrunner/Schema.rb, line 55
def date_with_weekday(timestamp)
  timestamp.strftime('%a, %Y %b %d %H:%M')
end