Class: Taxonifi::Model::SpeciesName

Inherits:
Base
  • Object
show all
Defined in:
lib/taxonifi/model/species_name.rb

Overview

The species name model is just a pointer to 5 Taxonifi::Model::Names. The various metadata (author, year, original combination) is stored with the individual instances of those names. Taxonifi::Model::Names have no ids!

Constant Summary collapse

ATTRIBUTES =
[:genus, :subgenus, :species, :subspecies, :variety, :parent]

Instance Attribute Summary

Attributes inherited from Base

#id, #properties, #row_number

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_properties, #add_property, #ancestor_ids, #ancestors, #build, #delete_property, #replace_property

Methods included from SharedClassMethods

included

Constructor Details

#initialize(options = {}) ⇒ SpeciesName

Returns a new instance of SpeciesName.



16
17
18
19
20
21
# File 'lib/taxonifi/model/species_name.rb', line 16

def initialize(options = {})
  opts = {
  }.merge!(options)
  build(ATTRIBUTES, opts)
  true
end

Class Method Details

.new_from_string(name) ⇒ Object

Create a new SpeciesName from a string format TODO: Is this replicated somewhere else? Examples:

Taxonifi::Model::SpeciesName.new_from_string('Aus bus Smith, 1920')
Taxonifi::Model::SpeciesName.new_from_string('Aus (Cus) bus dus (Smith, 1920)')


28
29
30
31
32
33
34
35
# File 'lib/taxonifi/model/species_name.rb', line 28

def self.new_from_string(name)
  raise Taxonifi::SpeciesNameError, "No name passed to SpeciesName.new_from_string" if name.nil? || name.length == 0 
  #  Appears to be a validly formatted species epithet at this point.
  lexer = Taxonifi::Splitter::Lexer.new(name, :species_name)
  builder = Taxonifi::Model::SpeciesName.new
  Taxonifi::Splitter::Parser.new(lexer, builder).parse_species_name
  builder
end

Instance Method Details

#display_nameObject

Return a string representation of the species name. Becuase we build parent relationships on setters this is the same as the last names display_name



91
92
93
# File 'lib/taxonifi/model/species_name.rb', line 91

def display_name
  names.last.display_name 
end

#genus=(genus) ⇒ Object

Set the genus name.



38
39
40
# File 'lib/taxonifi/model/species_name.rb', line 38

def genus=(genus)
  @genus = genus
end

#namesObject

Return an array of Name objects.



84
85
86
# File 'lib/taxonifi/model/species_name.rb', line 84

def names
  ATTRIBUTES.collect{|a| self.send(a)}.compact 
end

#nominotypical_genus?Boolean

Returns true if this combinations contains a nominotypic subgenus

Returns:

  • (Boolean)


101
102
103
# File 'lib/taxonifi/model/species_name.rb', line 101

def nominotypical_genus?
  names.genus && names.subgenus && (names.genus.name == names.subgenus.name)
end

#nominotypical_species?Boolean

Returns true if this combination contains a nominotypic subspecies name

Returns:

  • (Boolean)


96
97
98
# File 'lib/taxonifi/model/species_name.rb', line 96

def nominotypical_species?
  names.species && names.subspecies && (names.species.name == names.subspecies.name)
end

#parent=(parent) ⇒ Object

Set the parent name.



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/taxonifi/model/species_name.rb', line 71

def parent=(parent)
  if parent.class != Taxonifi::Model::Name
    raise SpeciesNameError, "Parent is not a Taxonifi::Model::Name."
  end

  if parent.rank.nil? ||  (Taxonifi::RANKS.index('genus') <= Taxonifi::RANKS.index(parent.rank))
    raise Taxonifi::SpeciesNameError, "Parents of SpeciesNames must have rank higher than Genus."
  end

  @parent = parent
end

#species=(species) ⇒ Object

Set the species name.



50
51
52
53
54
# File 'lib/taxonifi/model/species_name.rb', line 50

def species=(species)
  raise Taxonifi::SpeciesNameError, "Species name must have a Genus name before species can be assigned" if @genus.nil?
  @species = species 
  @species.parent = (@subgenus ? @subgenus : @genus)
end

#subgenus=(subgenus) ⇒ Object

Set the subgenus name.



43
44
45
46
47
# File 'lib/taxonifi/model/species_name.rb', line 43

def subgenus=(subgenus)
  raise Taxonifi::SpeciesNameError, "Species name must have a Genus name before subgenus can be assigned" if @genus.nil?
  @subgenus = subgenus
  @subgenus.parent = @genus
end

#subspecies=(subspecies) ⇒ Object

Set the subspecies name.



57
58
59
60
61
# File 'lib/taxonifi/model/species_name.rb', line 57

def subspecies=(subspecies)
  raise Taxonifi::SpeciesNameError, "Subspecies name must have a species name before species can be assigned" if @species.nil?
  @subspecies = subspecies 
  @subspecies.parent = @species
end

#variety=(variety) ⇒ Object

Set the variety name.



64
65
66
67
68
# File 'lib/taxonifi/model/species_name.rb', line 64

def variety=(variety)
  raise Taxonifi::SpeciesNameError, "Varieties name must have a species name before variety can be assigned" if @species.nil? 
  @variety = variety 
  @variety.parent = (@subspecies ? @subspecies : @species)
end