Class: MakeExportable::JSON
- Inherits:
-
ExportableFormat
- Object
- ExportableFormat
- MakeExportable::JSON
- Defined in:
- lib/make_exportable/exportable_formats/json.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 = []) ⇒ JSON
constructor
A new instance of JSON.
- #sanitize(value) ⇒ Object
Methods inherited from ExportableFormat
#generate_header_option, register_format
Constructor Details
#initialize(data_set, data_headers = []) ⇒ JSON
Returns a new instance of JSON.
10 11 12 13 14 15 |
# File 'lib/make_exportable/exportable_formats/json.rb', line 10 def initialize(data_set, data_headers=[]) self.long = "JavaScript Object Notation (JSON)" self.mime_type = "application/json; 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/json.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/json.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 29 30 |
# File 'lib/make_exportable/exportable_formats/json.rb', line 17 def generate output = [] unless data_headers.blank? data_set.each do |row| h = {} row.each_with_index do |field, i| h[data_headers[i]] = field end output << h end else end return output.to_json end |
#sanitize(value) ⇒ Object
32 33 |
# File 'lib/make_exportable/exportable_formats/json.rb', line 32 def sanitize(value) end |