Sha256: 1ffa7248d3090f68e667c62cfa82255f9b8e9d085825c7ed6060457ff67b1d36

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

# encoding: UTF-8
dir = File.dirname(__FILE__)
require File.join(dir, *%w[parser scientific_name_clean])
require File.join(dir, *%w[parser scientific_name_dirty])
require File.join(dir, *%w[parser scientific_name_canonical])
require 'rubygems'
require 'json'

class ScientificNameParser
  
  def initialize
    @verbatim = ''
    @clean = ScientificNameCleanParser.new
    @dirty = ScientificNameDirtyParser.new
    @canonical = ScientificNameCanonicalParser.new
    @parser = nil
  end
  
  def parse(a_string)
    @verbatim = a_string
    @parser = @clean.parse(a_string) || @dirty.parse(a_string) || @canonical.parse(a_string) || {:verbatim => a_string}
    def @parser.to_json
      parsed = self.class != Hash
      res = {:parsed => parsed}
      if parsed
        hybrid = self.hybrid rescue false
        res.merge!({
          :verbatim => self.text_value,
          :normalized => self.value,
          :canonical => self.canonical,
          :hybrid => hybrid,
          :details => self.details,
          :positions => self.pos
          })
      else
        res.merge!(self)
      end
      res = {:scientificName => res}
      JSON.generate res
    end
    
    def @parser.pos_json
      JSON.generate self.pos rescue ''
    end
    @parser
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dimus-biodiversity-0.5.10 lib/biodiversity/parser.rb
dimus-biodiversity-0.5.4 lib/biodiversity/parser.rb