Class: MakeExportable::TSV
- Inherits:
-
ExportableFormat
- Object
- ExportableFormat
- MakeExportable::TSV
- Defined in:
- lib/make_exportable/exportable_formats/tsv.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#data_headers ⇒ Object
Returns the value of attribute data_headers.
-
#data_set ⇒ Object
Returns the value of attribute data_set.
Attributes inherited from ExportableFormat
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(data_set, data_headers = []) ⇒ TSV
constructor
A new instance of TSV.
- #sanitize(value) ⇒ Object
Methods inherited from ExportableFormat
#generate_header_option, register_format
Constructor Details
#initialize(data_set, data_headers = []) ⇒ TSV
Returns a new instance of TSV.
10 11 12 13 14 15 |
# File 'lib/make_exportable/exportable_formats/tsv.rb', line 10 def initialize(data_set, data_headers=[]) self.long = "Tab-separated (TSV)" self.mime_type = "text/tab-separated-values; charset=utf-8;" self.data_set = data_set self.data_headers = data_headers end |
Instance Attribute Details
#data_headers ⇒ Object
Returns the value of attribute data_headers.
8 9 10 |
# File 'lib/make_exportable/exportable_formats/tsv.rb', line 8 def data_headers @data_headers end |
#data_set ⇒ Object
Returns the value of attribute data_set.
8 9 10 |
# File 'lib/make_exportable/exportable_formats/tsv.rb', line 8 def data_set @data_set end |
Instance Method Details
#generate ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/make_exportable/exportable_formats/tsv.rb', line 17 def generate generate_header_option(data_headers) output = "" unless data_headers.blank? output << data_headers.map {|h| sanitize(h.humanize.titleize) }.join("\t") end output << "\n" unless output.blank? data_set.each do |row| output << row.map {|field| sanitize(field)}.join("\t") << "\n" end return output end |
#sanitize(value) ⇒ Object
30 31 32 |
# File 'lib/make_exportable/exportable_formats/tsv.rb', line 30 def sanitize(value) value.gsub(/(\t|\\t)/, ' ') end |