Class: Biodiversity::Parser::GnParser::Csv

Inherits:
Biodiversity::Parser::GnParser
  • Object
show all
Defined in:
lib/biodiversity/parser/gnparser.rb

Overview

gnparser interface to CSV-formatted output

Instance Method Summary collapse

Instance Method Details

#formatObject



118
119
120
# File 'lib/biodiversity/parser/gnparser.rb', line 118

def format
  'csv'
end

#get_csv_value(csv, field_name) ⇒ Object



129
130
131
# File 'lib/biodiversity/parser/gnparser.rb', line 129

def get_csv_value(csv, field_name)
  csv[@csv_mapping[field_name]]
end

#init_gnparserObject



122
123
124
125
126
127
# File 'lib/biodiversity/parser/gnparser.rb', line 122

def init_gnparser
  @csv_mapping = {}
  CSV.new(@stdout.gets).read[0].each.with_index do |header, index|
    @csv_mapping[header] = index
  end
end

#parse_output(output) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/biodiversity/parser/gnparser.rb', line 101

def parse_output(output)
  parsed = CSV.new(output).first
  {
    id: get_csv_value(parsed, 'Id'),
    verbatim: get_csv_value(parsed, 'Verbatim'),
    cardinality: get_csv_value(parsed, 'Cardinality'),
    canonical: {
      stemmed: get_csv_value(parsed, 'CanonicalStem'),
      simple: get_csv_value(parsed, 'CanonicalSimple'),
      full: get_csv_value(parsed, 'CanonicalFull')
    },
    authorship: get_csv_value(parsed, 'Authorship'),
    year: get_csv_value(parsed, 'Year'),
    quality: get_csv_value(parsed, 'Quality')&.to_i
  }
end