Class: PostRunner::Schema
- Inherits:
-
Object
- Object
- PostRunner::Schema
- Defined in:
- lib/postrunner/Schema.rb
Overview
A Schema provides a unified way to query and process diverse data types.
Instance Attribute Summary collapse
-
#column_alignment ⇒ Object
readonly
Returns the value of attribute column_alignment.
-
#func ⇒ Object
readonly
Returns the value of attribute func.
-
#imperial_unit ⇒ Object
readonly
Returns the value of attribute imperial_unit.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#metric_unit ⇒ Object
readonly
Returns the value of attribute metric_unit.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(key, name, opts = {}) ⇒ Schema
constructor
Create a Schema object.
- #to_s(value) ⇒ Object
Constructor Details
#initialize(key, name, opts = {}) ⇒ Schema
Create a Schema object.
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_alignment ⇒ Object (readonly)
Returns the value of attribute column_alignment.
18 19 20 |
# File 'lib/postrunner/Schema.rb', line 18 def column_alignment @column_alignment end |
#func ⇒ Object (readonly)
Returns the value of attribute func.
18 19 20 |
# File 'lib/postrunner/Schema.rb', line 18 def func @func end |
#imperial_unit ⇒ Object (readonly)
Returns the value of attribute imperial_unit.
18 19 20 |
# File 'lib/postrunner/Schema.rb', line 18 def imperial_unit @imperial_unit end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
18 19 20 |
# File 'lib/postrunner/Schema.rb', line 18 def key @key end |
#metric_unit ⇒ Object (readonly)
Returns the value of attribute metric_unit.
18 19 20 |
# File 'lib/postrunner/Schema.rb', line 18 def metric_unit @metric_unit end |
#name ⇒ Object (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 |