Sha256: 12e769c59df76bf07422883f425c8e2f699d4890c51974dbbf0e5bc1e2ac3115

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 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
    @parsed = nil
  end
  
  def parse(a_string)
    @verbatim = a_string
    @parsed = @clean.parse(a_string) || @dirty.parse(a_string) || @canonical.parse(a_string) || {:verbatim => a_string}
    def @parsed.all
      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}
      res
    end
    
    def @parsed.pos_json
      JSON.generate self.pos rescue ''
    end
    
    def @parsed.all_json
      JSON.generate self.all
    end
    
    @parsed.all
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dimus-biodiversity-0.5.11 lib/biodiversity/parser.rb