Class: PostRunner::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/postrunner/Schema.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, name, opts = {}) ⇒ Schema

Create a Schema object.

Parameters:

  • key (Symbol)

    The globally unique identifier for the object

  • name (String)

    A human readable name to describe the object

  • opts (Hash) (defaults to: {})

    A Hash with values to overwrite the default values of some instance variables.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

Instance Attribute Details

#column_alignmentObject (readonly)

Returns the value of attribute column_alignment.



18
19
20
# File 'lib/postrunner/Schema.rb', line 18

def column_alignment
  @column_alignment
end

#funcObject (readonly)

Returns the value of attribute func.



18
19
20
# File 'lib/postrunner/Schema.rb', line 18

def func
  @func
end

#imperial_unitObject (readonly)

Returns the value of attribute imperial_unit.



18
19
20
# File 'lib/postrunner/Schema.rb', line 18

def imperial_unit
  @imperial_unit
end

#keyObject (readonly)

Returns the value of attribute key.



18
19
20
# File 'lib/postrunner/Schema.rb', line 18

def key
  @key
end

#metric_unitObject (readonly)

Returns the value of attribute metric_unit.



18
19
20
# File 'lib/postrunner/Schema.rb', line 18

def metric_unit
  @metric_unit
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/postrunner/Schema.rb', line 18

def name
  @name
end

Instance Method Details

#to_s(value) ⇒ Object



48
49
50
51
# File 'lib/postrunner/Schema.rb', line 48

def to_s(value)
  value = send(@format, value) if @format
  value.to_s
end