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.
69 70 71 72 73 74 75 76 |
# File 'lib/rarff.rb', line 69 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.
67 68 69 |
# File 'lib/rarff.rb', line 67 def type @type end |
Instance Method Details
#add_nominal_value(str) ⇒ Object
98 99 100 101 102 103 104 |
# 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 ⇒ Object
Convert string representation of nominal type to array, if necessary TODO: This might falsely trigger on wacky date formats.
87 88 89 90 91 92 93 94 95 |
# 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 ⇒ Object
107 108 109 110 111 112 113 |
# 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 ⇒ Object
116 117 118 |
# File 'lib/rarff.rb', line 116 def to_s to_arff end |