class Taxonifi::Model::Name

A taxonomic name.

Constants

ATTRIBUTES

Array, contains properties assignable in Taxonifi::Model::Name#new()

Attributes

author[RW]

String

author_year_index[RW]

optionally parsed/index

authors[RW]

optionally parsed/index

name[RW]

String

parens[RW]

Boolean, true if parens present (i.e. not in original combination)

parent[RW]
rank[RW]

String

year[RW]

String, authors as originally read

Public Class Methods

new(options = {}) click to toggle source
# File lib/models/name.rb, line 35
def initialize(options = {})
  opts = {
    id: nil
  }.merge!(options)
  @parent = nil
  build(ATTRIBUTES, opts)
  add_author_year(opts[:author_year]) if !opts[:author_year].nil? && opts[:author_year].size > 0
  @parent = opts[:parent] if (!opts[:parent].nil? && opts[:parent].class == Taxonifi::Model::Name)
  @id = opts[:id] # if !opts[:id].nil? && opts[:id].size != 0
  @authors ||= []
  true
end

Public Instance Methods

add_author_year(string) { |Array of Person| ... } click to toggle source

Returns an Array of Taxonifi::Model::Person

# File lib/models/name.rb, line 49
def add_author_year(string) # :yields: Array of Taxonifi::Model::Person
  auth_yr = Taxonifi::Splitter::Builder.build_author_year(string)
  @year = auth_yr.year
  @authors = auth_yr.people
end
author_year() click to toggle source

Returns a formatted string, including parens for the name TODO: rename to reflect parens

# File lib/models/name.rb, line 90
def author_year
  au = author_year_string
  if self.parens == false
    "(#{au})"        
  else
    au.size == 0 ? nil : au
  end
end
author_year_string() click to toggle source

Return the author year string.

# File lib/models/name.rb, line 100
def author_year_string
  au = [self.author, self.year].compact.join(", ")
end
derive_authors_year() click to toggle source

Translates the String representation of author year to an Array of People. Used in indexing, when comparing Name microtations to Ref microcitations.

# File lib/models/name.rb, line 57
def derive_authors_year
  add_author_year(author_year_string) 
end
display_name() click to toggle source

Return the human readable version of this name with author year (String)

# File lib/models/name.rb, line 134
def display_name
  [nomenclator_name, author_year].compact.join(" ")
end
generate_author_year_index() click to toggle source

Generate/return the author year index.

# File lib/models/name.rb, line 175
def generate_author_year_index
  @author_year_index = Taxonifi::Model::AuthorYear.new(people: @authors, year: @year).compact_index
end
nomenclator_name() click to toggle source

Return the human readable version of this name, without author year (String)

# File lib/models/name.rb, line 139
def nomenclator_name 
  case @rank
  when 'species', 'subspecies'
    [parent_name_at_rank('genus'), (parent_name_at_rank('subgenus') ? "({parent_name_at_rank('subgenus')})" : nil), parent_name_at_rank('species'), @name].compact.join(" ")
  when 'subgenus'
    [parent_name_at_rank('genus'), "(#{@name})"].compact.join(" ")
  else
    [@name].compact.join(" ")
  end
end
parent=(parent) click to toggle source

Set the parent (a Taxonifi::Model::Name)

# File lib/models/name.rb, line 71
def parent=(parent)
  if @rank.nil?
    raise Taxonifi::NameError, "Parent of name can not be set if rank of child is not set." 
  end

  # TODO: ICZN class over-ride
  if parent.class != Taxonifi::Model::Name
    raise NameError, "Parent is not a Taxonifi::Model::Name."
  end

  if RANKS.index(parent.rank) >= RANKS.index(self.rank)
    raise NameError, "Parent is same or lower rank than self (#{rank})."
  end

  @parent = parent
end
parent_at_rank(rank) click to toggle source

Return the parent at a given rank. TODO: move method to Base?

# File lib/models/name.rb, line 121
def parent_at_rank(rank)
  return self if self.rank == rank
  p = @parent
  i = 0
  while !p.nil?
    return p if p.rank == rank
    p = p.parent
    raise NameError, "Loop detected among parents fo [#{self.display_name}]" if i > 75 
  end
  nil 
end
parent_ids_sf_style() click to toggle source

Return a dashed “vector” of ids representing the ancestor parent closure, like:

0-1-14-29g-45s-99-100.
Postfixed g means "genus", postifed s means "subgenus.  As per SpecieFile usage.
# File lib/models/name.rb, line 153
def parent_ids_sf_style
  ids = [] 
  (ancestors.push self).each do |a|
    case a.rank
    when 'genus'
      ids.push "#{a.id}g"
    when 'subgenus'
      ids.push "#{a.id}s"
    else
      ids.push a.id.to_s
    end
  end

  ids.join("-")
end
parent_name_at_rank(rank) click to toggle source

Return the name of a parent at a given rank. TODO: move method to Base?

# File lib/models/name.rb, line 106
def parent_name_at_rank(rank)
  return self.name if self.rank == rank
  p = @parent
  i = 0
  while !p.nil?
    return p.name if p.rank == rank
    p = p.parent
    i+= 1
    raise NameError, "Loop detected among parents for [#{self.display_name}]." if i > 75 
  end
  nil 
end
rank=(rank) click to toggle source

Set the rank.

# File lib/models/name.rb, line 62
def rank=(rank)
  r = rank.to_s.downcase.strip
  if !RANKS.include?(r) 
    raise NameError, "#{r} is not a valid rank."
  end
  @rank = r
end