class Taxonifi::Splitter::Parser

Parser pattern taken from OboParser and other mjy gems.

The parser takes a builder and a lexer and does the actual breakdown.

Public Class Methods

new(lexer, builder ) click to toggle source
# File lib/splitter/parser.rb, line 7
def initialize(lexer, builder )
  @lexer = lexer
  @builder = builder

Public Instance Methods

parse_author_year() click to toggle source

parse out an author year combination. TODO: This is only indirectly tested in lumper code

# File lib/splitter/parser.rb, line 14
def parse_author_year
  t = @lexer.pop(Taxonifi::Splitter::Tokens::AuthorYear)

  lexer =
  authors = lexer.pop(Taxonifi::Splitter::Tokens::Authors)

  # TODO: A people collection?
  authors.names.each do |a|
    n =
    n.last_name = a[:last_name]
    n.initials = a[:initials]
    @builder.people.push n 

  @builder.year   = t.year.to_i
  @builder.parens = t.parens
parse_species_name() click to toggle source

Parse a species name

# File lib/splitter/parser.rb, line 33
def parse_species_name
  t = @lexer.pop(Taxonifi::Splitter::Tokens::Quadrinomial)
  ranks = %w{genus subgenus species subspecies}
  names = {} 
  last_parent = nil
  ranks.each do |r|
    names.merge!(r: nil)
    @builder.send("#{r}=", => t.send(r), rank: r) ) if t.send(r)

  if @lexer.peek(Taxonifi::Splitter::Tokens::AuthorYear)
    t = @lexer.pop(Taxonifi::Splitter::Tokens::AuthorYear) = t.authors
    @builder.names.last.year = t.year
    @builder.names.last.parens = !t.parens