class Rarff::Attribute

Attributes

name[RW]
type[R]

Public Class Methods

new(name='', type='') click to toggle source
# File lib/rarff.rb, line 69
def initialize(name='', type='')
  @name = name

  @type_is_nominal = false
  @type = type

  check_nominal()
end

Public Instance Methods

add_nominal_value(str) click to toggle source
# File lib/rarff.rb, line 98
def add_nominal_value(str)
  if @type_is_nominal == false
    @type = Array.new
  end

  @type << str
end
check_nominal() click to toggle source

Convert string representation of nominal type to array, if necessary TODO: This might falsely trigger on wacky date formats.

# File lib/rarff.rb, line 87
def check_nominal
  if @type =~ /^\s*\{.*(\,.*)+\}\s*$/
    @type_is_nominal = true
    # Example format: "{nom1,nom2, nom3, nom4,nom5 } "
    # Split on '{'  ','  or  '}'
    #        @type = @type.gsub(/^\s*\{\s*/, '').gsub(/\s*\}\s*$/, '').split(/\s*\,\s*/)
    @type = @type.split(/\s*\,\s*/)
  end
end
to_arff() click to toggle source
# File lib/rarff.rb, line 107
def to_arff
  if @type_is_nominal == true
    ATTRIBUTE_MARKER + " #{@name} #{@type.join(',').gsub(' ','_')}"
  else
    ATTRIBUTE_MARKER + " #{@name} #{@type}"
  end
end
to_s() click to toggle source
# File lib/rarff.rb, line 116
def to_s
  to_arff
end
type=(type) click to toggle source
# File lib/rarff.rb, line 79
def type=(type)
  @type = type
  check_nominal()
end