Class: Unidata::Field
- Inherits:
-
Object
- Object
- Unidata::Field
- Defined in:
- lib/unidata/field.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #default ⇒ Object
- #from_unidata(value) ⇒ Object
-
#initialize(index, name, type = String, options = {}) ⇒ Field
constructor
A new instance of Field.
- #to_unidata(value) ⇒ Object
- #typecast(value) ⇒ Object
Constructor Details
#initialize(index, name, type = String, options = {}) ⇒ Field
Returns a new instance of Field.
5 6 7 8 9 10 11 12 |
# File 'lib/unidata/field.rb', line 5 def initialize(index, name, type=String, ={}) @index = [*index] @name = name @type = type @default = [:default] raise ArgumentError, 'index must be 1-3 levels' if @index.size > 3 end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
3 4 5 |
# File 'lib/unidata/field.rb', line 3 def index @index end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/unidata/field.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/unidata/field.rb', line 3 def type @type end |
Instance Method Details
#default ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/unidata/field.rb', line 14 def default if @default.respond_to?(:call) @default.call else @default end end |
#from_unidata(value) ⇒ Object
30 31 32 |
# File 'lib/unidata/field.rb', line 30 def from_unidata(value) type.from_unidata(value) end |
#to_unidata(value) ⇒ Object
26 27 28 |
# File 'lib/unidata/field.rb', line 26 def to_unidata(value) type.to_unidata(value) end |
#typecast(value) ⇒ Object
22 23 24 |
# File 'lib/unidata/field.rb', line 22 def typecast(value) type.typecast(value) end |