A taxonomic name.
Array, contains properties assignable in Taxonifi::Model::Name#new()
String
Boolean, true if parens present (i.e. not in original combination)
String
String, authors as originally read
# 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
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
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
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
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
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
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
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