Class: Unidata::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/unidata/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, name, type = String, options = {}) ⇒ Field

Returns a new instance of Field.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
# File 'lib/unidata/field.rb', line 5

def initialize(index, name, type=String, options={})
  @index = [*index]
  @name = name
  @type = type
  @default = options[:default]

  raise ArgumentError, 'index must be 1-3 levels' if @index.size > 3
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



3
4
5
# File 'lib/unidata/field.rb', line 3

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/unidata/field.rb', line 3

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/unidata/field.rb', line 3

def type
  @type
end

Instance Method Details

#defaultObject



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