Class: MakeExportable::JSON

Inherits:
ExportableFormat show all
Defined in:
lib/make_exportable/exportable_formats/json.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from ExportableFormat

#long, #mime_type

Instance Method Summary collapse

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_headersObject

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_setObject

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

#generateObject



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