Class: Taxonifi::Model::Name
Overview
A taxonomic name.
Direct Known Subclasses
Constant Summary collapse
- @@ATTRIBUTES =
An Array, contains assignable properties in Taxonifi::Model::Name#new()
[:name, :rank, :year, :parens, :author, :related_name ]
Constants inherited from Base
Instance Attribute Summary collapse
-
#author ⇒ Object
String, authors as originally read.
-
#author_year_index ⇒ Object
Return a Taxonifi::Model::AuthorYear representing author/year !! Identical to method in Taxonifi::Model::Ref !! Not necessarily unique.
-
#authors ⇒ Object
An Array of Taxonifi::Model::Person Optionally parsed/index.
-
#name ⇒ Object
String.
-
#original_description_reference ⇒ Object
A Taxonifi::Model::Reference The original description.
-
#parens ⇒ Object
Boolean, true if parens present (i.e. not in original combination).
-
#parent ⇒ Object
A Taxonifi::Model::Name.
-
#rank ⇒ Object
String.
-
#related_name ⇒ Object
A Taxonifi::Model::Name A general purpose relationship, typically used to indicate synonymy.
-
#year ⇒ Object
String, year as originally read.
Attributes inherited from Base
Instance Method Summary collapse
-
#add_author_year(string) ⇒ Object
Returns an Array of Taxonifi::Model::Person.
-
#author_year ⇒ Object
Returns a formatted string, including parens for the name TODO: rename to reflect parens.
-
#author_year_string ⇒ Object
Return the author year string.
-
#derive_authors_year ⇒ Object
Translates the String representation of author year to an Array of People.
-
#display_name ⇒ Object
Return a String, the human readable version of this name (genus, subgenus, species, subspecies, variety author, year).
-
#generate_author_year_index ⇒ Object
Generate and return (String) the author year index.
-
#genus_group? ⇒ Boolean
TODO: test Returne True of False based on @rank.
-
#genus_group_parent ⇒ Object
Return a Taxonifi::Model::Name representing the finest genus_group_parent.
-
#index_rank ⇒ Object
Return a string indicating at what level this name is indexed within a NameCollection.
-
#initialize(options = {}) ⇒ Name
constructor
A new instance of Name.
-
#name_author_year_string ⇒ Object
Returns just the name and author year, no parens, no parents.
-
#nomenclator_array ⇒ Object
Return an Array of lenght 4 of Names representing a Species or Genus group name [genus, subgenus, species, subspecies, infrasubspecific].
-
#nomenclator_name ⇒ Object
Return a String, the human readable version of this name (genus, subgenus, species, subspecies).
-
#nomenclator_name? ⇒ Boolean
Return a Boolean, True if @rank is one of ‘genus’, ‘subgenus’, ‘species’, ‘subspecies’ TODO: update for infrasubspecifics if we start tracking those.
-
#parent_at_rank(rank) ⇒ Object
Return the parent at a given rank.
-
#parent_ids_sf_style ⇒ Object
0-1-14-29g-45s-99-100.
-
#parent_name_at_rank(rank) ⇒ Object
Return the name of a parent at a given rank.
-
#prologify ⇒ Object
Return a String of Prolog rules representing this Name.
-
#species_group? ⇒ Boolean
TODO: test Returne True of False based on @rank.
Methods inherited from Base
#add_properties, #add_property, #ancestor_ids, #ancestors, #build, #delete_property, #replace_property
Methods included from SharedClassMethods
Constructor Details
#initialize(options = {}) ⇒ Name
Returns a new instance of Name.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/taxonifi/model/name.rb', line 43 def initialize( = {}) super opts = { id: nil }.merge!() @parent = nil ||= [] build(@@ATTRIBUTES, opts) (opts) @id = opts[:id] @parent = opts[:parent] if (!opts[:parent].nil? && opts[:parent].class == Taxonifi::Model::Name) @original_description_reference = opts[:original_description_reference] if (!opts[:original_description_reference].nil? && opts[:original_description_reference].class == Taxonifi::Model::Ref) true end |
Instance Attribute Details
#author ⇒ Object
String, authors as originally read
14 15 16 |
# File 'lib/taxonifi/model/name.rb', line 14 def end |
#author_year_index ⇒ Object
Return a Taxonifi::Model::AuthorYear representing author/year !! Identical to method in Taxonifi::Model::Ref !! Not necessarily unique.
41 42 43 |
# File 'lib/taxonifi/model/name.rb', line 41 def end |
#authors ⇒ Object
An Array of Taxonifi::Model::Person Optionally parsed/index
38 39 40 |
# File 'lib/taxonifi/model/name.rb', line 38 def end |
#name ⇒ Object
String
8 9 10 |
# File 'lib/taxonifi/model/name.rb', line 8 def name @name end |
#original_description_reference ⇒ Object
A Taxonifi::Model::Reference The original description.
31 32 33 |
# File 'lib/taxonifi/model/name.rb', line 31 def original_description_reference @original_description_reference end |
#parens ⇒ Object
Boolean, true if parens present (i.e. not in original combination)
20 21 22 |
# File 'lib/taxonifi/model/name.rb', line 20 def parens @parens end |
#parent ⇒ Object
A Taxonifi::Model::Name
23 24 25 |
# File 'lib/taxonifi/model/name.rb', line 23 def parent @parent end |
#rank ⇒ Object
String
11 12 13 |
# File 'lib/taxonifi/model/name.rb', line 11 def rank @rank end |
#related_name ⇒ Object
A Taxonifi::Model::Name A general purpose relationship, typically used to indicate synonymy.
27 28 29 |
# File 'lib/taxonifi/model/name.rb', line 27 def end |
#year ⇒ Object
String, year as originally read
17 18 19 |
# File 'lib/taxonifi/model/name.rb', line 17 def year @year end |
Instance Method Details
#add_author_year(string) ⇒ Object
Returns an Array of Taxonifi::Model::Person
64 65 66 67 68 |
# File 'lib/taxonifi/model/name.rb', line 64 def (string) # :yields: Array of Taxonifi::Model::Person auth_yr = Taxonifi::Splitter::Builder.(string) @year = auth_yr.year = auth_yr.people end |
#author_year ⇒ Object
Returns a formatted string, including parens for the name TODO: rename to reflect parens
124 125 126 127 128 |
# File 'lib/taxonifi/model/name.rb', line 124 def au = return nil if au.nil? (self.parens == true) ? "(#{au})" : au end |
#author_year_string ⇒ Object
Return the author year string.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/taxonifi/model/name.rb', line 132 def # Build based on People auth = nil if .size > 0 case .size when 1 auth = self. when 2 auth = .map(&:last_name).join(" & ") when 2...100 auth = [0..-1].map(&:last_name).join(", ") + " & " + .last.last_name end # Build based on string else auth = self. end au = [auth, self.year].compact.join(", ") return nil if au.size == 0 au end |
#derive_authors_year ⇒ Object
Translates the String representation of author year to an Array of People. Used in indexing, when comparing Name microtations to Ref microcitations.
72 73 74 |
# File 'lib/taxonifi/model/name.rb', line 72 def () end |
#display_name ⇒ Object
Return a String, the human readable version of this name (genus, subgenus, species, subspecies, variety author, year)
155 156 157 |
# File 'lib/taxonifi/model/name.rb', line 155 def display_name [nomenclator_name, ].compact.join(" ") end |
#generate_author_year_index ⇒ Object
Generate and return (String) the author year index.
265 266 267 |
# File 'lib/taxonifi/model/name.rb', line 265 def = Taxonifi::Model::AuthorYear.new(people: , year: @year).compact_index end |
#genus_group? ⇒ Boolean
TODO: test Returne True of False based on @rank
277 278 279 |
# File 'lib/taxonifi/model/name.rb', line 277 def genus_group? true if @rank == 'genus' || @rank == 'subgenus' end |
#genus_group_parent ⇒ Object
Return a Taxonifi::Model::Name representing the finest genus_group_parent. TODO: ICZN specific(?)
196 197 198 |
# File 'lib/taxonifi/model/name.rb', line 196 def genus_group_parent [ parent_at_rank('subgenus'), parent_at_rank('genus')].compact.first end |
#index_rank ⇒ Object
Return a string indicating at what level this name is indexed within a NameCollection. TODO: Family group extension; ICZN specific
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/taxonifi/model/name.rb', line 88 def index_rank case rank when 'species', 'subspecies', 'variety' 'species_group' when 'genus', 'subgenus' 'genus_group' when nil, "" 'unknown' else rank.downcase end end |
#name_author_year_string ⇒ Object
Returns just the name and author year, no parens, no parents. Like:
foo Smith, 1927
Foo Smith, 1927
Fooidae
205 206 207 |
# File 'lib/taxonifi/model/name.rb', line 205 def [name, ].compact.join(" ") end |
#nomenclator_array ⇒ Object
Return an Array of lenght 4 of Names representing a Species or Genus group name
- genus, subgenus, species, subspecies, infrasubspecific
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/taxonifi/model/name.rb', line 178 def nomenclator_array case @rank when 'variety' return [parent_name_at_rank('genus'), (parent_name_at_rank('subgenus') ? "(#{parent_name_at_rank('subgenus')})" : nil), parent_name_at_rank('species'), parent_name_at_rank('subspecies'), "var. #{@name}"] when 'species', 'subspecies' return [parent_name_at_rank('genus'), (parent_name_at_rank('subgenus') ? "(#{parent_name_at_rank('subgenus')})" : nil), parent_name_at_rank('species'), parent_name_at_rank('subspecies'), nil] when 'subgenus' return [parent_name_at_rank('genus'), "(#{@name})", nil, nil, nil] when 'genus' return [@name, nil, nil, nil, nil] else return false end end |
#nomenclator_name ⇒ Object
Return a String, the human readable version of this name (genus, subgenus, species, subspecies)
160 161 162 163 164 165 166 167 168 |
# File 'lib/taxonifi/model/name.rb', line 160 def nomenclator_name case @rank # TODO: update for infrasubspecifics if we start tracking those when 'species', 'subspecies', 'genus', 'subgenus', 'variety' nomenclator_array.compact.join(" ") else @name end end |
#nomenclator_name? ⇒ Boolean
Return a Boolean, True if @rank is one of ‘genus’, ‘subgenus’, ‘species’, ‘subspecies’ TODO: update for infrasubspecifics if we start tracking those
172 173 174 |
# File 'lib/taxonifi/model/name.rb', line 172 def nomenclator_name? %w{genus subgenus species subspecies variety}.include?(@rank) end |
#parent_at_rank(rank) ⇒ Object
Return the parent at a given rank. TODO: move method to Base?
226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/taxonifi/model/name.rb', line 226 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 ⇒ Object
0-1-14-29g-45s-99-100.
Postfixed g means "genus", postifed s means "subgenus. As per SpecieFile usage.
TODO: !! malformed because the valid name is not injected. Note that this can be generated internally post import.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/taxonifi/model/name.rb', line 242 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) ⇒ Object
Return the name of a parent at a given rank. TODO: move method to Base?
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/taxonifi/model/name.rb', line 211 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 |
#prologify ⇒ Object
Return a String of Prolog rules representing this Name
282 283 284 |
# File 'lib/taxonifi/model/name.rb', line 282 def prologify "false" end |
#species_group? ⇒ Boolean
TODO: test Returne True of False based on @rank
271 272 273 |
# File 'lib/taxonifi/model/name.rb', line 271 def species_group? true if @rank == 'species' || @rank == 'subspecies' end |