Class: Rarff::Attribute
- Inherits:
-
Object
- Object
- Rarff::Attribute
- Defined in:
- lib/rarff.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_nominal_value(str) ⇒ Object
-
#check_nominal ⇒ Object
Convert string representation of nominal type to array, if necessary TODO: This might falsely trigger on wacky date formats.
-
#initialize(name = '', type = '') ⇒ Attribute
constructor
A new instance of Attribute.
- #to_arff ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name = '', type = '') ⇒ Attribute
Returns a new instance of Attribute.
68 69 70 71 72 73 74 75 |
# File 'lib/rarff.rb', line 68 def initialize(name='', type='') @name = name @type_is_nominal = false @type = type check_nominal() end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
66 67 68 |
# File 'lib/rarff.rb', line 66 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
66 67 68 |
# File 'lib/rarff.rb', line 66 def type @type end |
Instance Method Details
#add_nominal_value(str) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/rarff.rb', line 96 def add_nominal_value(str) if @type_is_nominal == false @type = Array.new end @type << str end |
#check_nominal ⇒ Object
Convert string representation of nominal type to array, if necessary TODO: This might falsely trigger on wacky date formats.
86 87 88 89 90 91 92 93 |
# File 'lib/rarff.rb', line 86 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*/) end end |
#to_arff ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/rarff.rb', line 105 def to_arff if @type_is_nominal == true ATTRIBUTE_MARKER + " #{@name} {#{@type.join(',').gsub(' ','_')}}" else ATTRIBUTE_MARKER + " #{@name} #{@type}" end end |
#to_s ⇒ Object
114 115 116 |
# File 'lib/rarff.rb', line 114 def to_s to_arff end |