Parser pattern taken from OboParser and other mjy gems.
The parser takes a builder and a lexer and does the actual breakdown.
# File lib/splitter/parser.rb, line 7 def initialize(lexer, builder ) @lexer = lexer @builder = builder end
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}=", Taxonifi::Model::Name.new(:name => t.send(r), rank: r) ) if t.send(r) end if @lexer.peek(Taxonifi::Splitter::Tokens::AuthorYear) t = @lexer.pop(Taxonifi::Splitter::Tokens::AuthorYear) @builder.names.last.author = t.authors @builder.names.last.year = t.year @builder.names.last.parens = !t.parens @builder.names.last.derive_authors_year end @builder end