Class: Gdt::GdtField

Inherits:
Struct
  • Object
show all
Defined in:
lib/gdt/field_handling.rb

Constant Summary collapse

TYPES =
{
  :num => lambda { |v| v.to_i },
  :alnum => lambda { |v| ::Iconv.new("UTF-8","CP850").iconv(v) },
  :datum => lambda { |v| ::Date.new(*v.scan(/(..)(..)(....)/)[0].map {|x| x.to_i }.reverse) rescue nil }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



6
7
8
# File 'lib/gdt/field_handling.rb', line 6

def description
  @description
end

#lengthObject

Returns the value of attribute length

Returns:

  • (Object)

    the current value of length



6
7
8
# File 'lib/gdt/field_handling.rb', line 6

def length
  @length
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



6
7
8
# File 'lib/gdt/field_handling.rb', line 6

def name
  @name
end

#rulesObject

Returns the value of attribute rules

Returns:

  • (Object)

    the current value of rules



6
7
8
# File 'lib/gdt/field_handling.rb', line 6

def rules
  @rules
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



6
7
8
# File 'lib/gdt/field_handling.rb', line 6

def type
  @type
end

Instance Method Details

#verify_and_convert(value) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/gdt/field_handling.rb', line 29

def verify_and_convert(value)
  # check length
  #
  if @length
    message = "the field #{name.inspect} does not have the correct length, expected (#{@length.inspect})"
    # ignore length checks for now
    # raise ArgumentError, message unless @length.include?(value.length)
  end
  TYPES[self.type].call(value)
end