Class: Unipept::JSONFormatter

Inherits:
Formatter show all
Defined in:
lib/formatters.rb

Instance Method Summary collapse

Methods inherited from Formatter

available, default, #format, formatters, #group_by_first_key, hidden?, #integrate_fasta_headers, new_for_format, register

Instance Method Details

#convert(data, first) ⇒ String

Converts the given input data to the JSON format.

Parameters:

  • data (Array)

    The data we wish to convert

  • Is (Boolean)

    this the first output batch?

Returns:

  • (String)

    The converted input data in the JSON format



157
158
159
160
# File 'lib/formatters.rb', line 157

def convert(data, first)
  output = data.map(&:to_json).join(',')
  first ? output : ",#{output}"
end


146
147
148
# File 'lib/formatters.rb', line 146

def footer
  "]\n"
end

#header(_data, _fasta_mapper = nil) ⇒ Object



142
143
144
# File 'lib/formatters.rb', line 142

def header(_data, _fasta_mapper = nil)
  '['
end

#typeString

Returns The type of the current formatter: json.

Returns:

  • (String)

    The type of the current formatter: json



138
139
140
# File 'lib/formatters.rb', line 138

def type
  'json'
end