lib/data_frame/arff.rb in davidrichards-data_frame-0.0.18 vs lib/data_frame/arff.rb in davidrichards-data_frame-0.0.19
- old
+ new
@@ -1,45 +1,52 @@
-# Turns a data frame into ARFF-formatted content.
-module ARFF
+module DF #:nodoc:
+ # Turns a data frame into ARFF-formatted content.
+ module ARFF
- # Used in arff, but generally useful.
- def to_csv(include_header=true)
- value = include_header ? self.labels.map{|e| e.to_s}.join(',') + "\n" : ''
- self.items.inject(value) do |list, e|
- list << e.map {|cell| cell.to_s}.join(',') + "\n"
+ # Used in arff, but generally useful.
+ def to_csv(include_header=true)
+ value = include_header ? self.labels.map{|e| e.to_s}.join(',') + "\n" : ''
+ self.items.inject(value) do |list, e|
+ list << e.map {|cell| cell.to_s}.join(',') + "\n"
+ end
end
- end
- def to_arff
- arff_header + to_csv(false)
- end
-
- protected
- def arff_attributes
- container = defined?(Dictionary) ? Dictionary.new : Hash.new
-
- self.labels.inject(container) do |list, e|
- list[e] = self.render_column(e).categories
- end
+ def to_arff
+ arff_header + to_csv(false)
end
-
- def arff_formatted_attributes
- self.labels.inject('') do |str, e|
- val = "{" + self.render_column(e).categories.map{|x| x.to_s}.join(',') + "}"
- str << "@attribute #{e} #{val}\n"
+
+ protected
+ def arff_attributes
+ container = defined?(Dictionary) ? Dictionary.new : Hash.new
+
+ self.labels.inject(container) do |list, e|
+ list[e] = self.render_column(e).categories
+ end
end
- end
-
- def arff_relation
- self.name ? self.name.to_underscore_sym.to_s : 'unamed_relation'
- end
-
- def arff_header
- %[@relation #{arff_relation}
+ def arff_formatted_attributes
+ self.labels.inject('') do |str, e|
+ val = "{" + self.render_column(e).categories.map{|x| x.to_s}.join(',') + "}"
+ str << "@attribute #{e} #{val}\n"
+ end
+ end
+
+ def arff_relation
+ self.name ? self.name.to_underscore_sym.to_s : 'unamed_relation'
+ end
+
+ def arff_header
+ %[@relation #{arff_relation}
+
#{arff_formatted_attributes}
@data
]
- end
-
- alias :arff_items :to_csv
+ end
+
+ alias :arff_items :to_csv
+ end
+
+end
+
+class DataFrame
+ include DF::ARFF
end
\ No newline at end of file