Skip to content
Browse files

escape commas in string definitions

  • Loading branch information...
1 parent 6876915 commit fdaafb1768655826b439a67245ed6c6a99783b0a iterationlabs committed with Ben J Woodcroft
Showing with 3 additions and 4 deletions.
  1. +1 −2 lib/rarff.rb
  2. +2 −2 test/test_rarff.rb
View
3 lib/rarff.rb
@@ -253,7 +253,6 @@ def expand_sparse(str)
def to_arff(sparse=false)
RELATION_MARKER + " #{@name}\n" +
-# @attributes.map{ |attr| attr.to_arff }.join("\n") +
@attributes.join("\n") +
"\n" +
DATA_MARKER + "\n" +
@@ -265,7 +264,7 @@ def to_arff(sparse=false)
# quotes or are already quoted.
unless col.nil?
if @attributes[i].type =~ /^#{ATTRIBUTE_STRING}$/i
- if col =~ /\s+/
+ if col =~ /[,\s+]/
col = "'" + col + "'"
end
elsif @attributes[i].type =~ /^#{ATTRIBUTE_DATE}/i ## Hack comparison. Ugh.
View
4 test/test_rarff.rb
@@ -17,7 +17,7 @@ def test_arff_creation
@ATTRIBUTE birthday DATE "yyyy-MM-dd HH:mm:ss"
@DATA
1.4, 'foo bar', 5, baz, "1900-08-08 12:12:12"
-20.9, ruby, 46, rocks, "2005-10-23 12:12:12"
+20.9, ruby, 46, 'roc,ks', "2005-10-23 12:12:12"
0, ruby, 46, rocks, "2001-02-19 12:12:12"
68.1, stuff, 728, 'is cool', "1974-02-10 12:12:12"
END_OF_ARFF_FILE
@@ -25,7 +25,7 @@ def test_arff_creation
arff_file_str.gsub!(/\n$/, '')
instances = [ [1.4, 'foo bar', 5, 'baz', "1900-08-08 12:12:12"],
- [20.9, 'ruby', 46, 'rocks', "2005-10-23 12:12:12"],
+ [20.9, 'ruby', 46, 'roc,ks', "2005-10-23 12:12:12"],
[0, 'ruby', 46, 'rocks', "2001-02-19 12:12:12"],
[68.1, 'stuff', 728, 'is cool', "1974-02-10 12:12:12"]]

0 comments on commit fdaafb1

Please sign in to comment.
Something went wrong with that request. Please try again.