Class: Biodiversity::Parser::GnParser::Csv
- Inherits:
-
Biodiversity::Parser::GnParser
- Object
- Biodiversity::Parser::GnParser
- Biodiversity::Parser::GnParser::Csv
- Defined in:
- lib/biodiversity/parser/gnparser.rb
Overview
gnparser interface to CSV-formatted output
Instance Method Summary collapse
- #format ⇒ Object
- #get_csv_value(csv, field_name) ⇒ Object
- #init_gnparser ⇒ Object
- #parse_output(output) ⇒ Object
Instance Method Details
#format ⇒ Object
130 131 132 |
# File 'lib/biodiversity/parser/gnparser.rb', line 130 def format 'csv' end |
#get_csv_value(csv, field_name) ⇒ Object
141 142 143 |
# File 'lib/biodiversity/parser/gnparser.rb', line 141 def get_csv_value(csv, field_name) csv[@csv_mapping[field_name]] end |
#init_gnparser ⇒ Object
134 135 136 137 138 139 |
# File 'lib/biodiversity/parser/gnparser.rb', line 134 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
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/biodiversity/parser/gnparser.rb', line 113 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 |