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_string ⇒ Object
return [String] an author string.
-
#author_with_parens ⇒ Object
return [String] an author string, including parens for the name.
-
#author_year ⇒ Object
TODO: rename to reflect parens return [String] an author/year string, including parens for the name.
-
#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 @authors ||= [] 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 @author 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 @author_year_index end |
#authors ⇒ Object
An Array of Taxonifi::Model::Person Optionally parsed/index
38 39 40 |
# File 'lib/taxonifi/model/name.rb', line 38 def @authors 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 @related_name 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 @authors = auth_yr.people end |
#author_string ⇒ Object
return [String] an author string
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/taxonifi/model/name.rb', line 148 def auth = nil if .size > 0 # Build based on People case .size when 1 auth = .first.last_name # self.author when 2 auth = .map(&:last_name).join(" & ") when 3...100 auth = [0..-1].map(&:last_name).join(", ") + " & " + .last.last_name end else # Build based on string auth = self. end auth end |
#author_with_parens ⇒ Object
return [String] an author string, including parens for the name
141 142 143 144 145 |
# File 'lib/taxonifi/model/name.rb', line 141 def au = return nil if au.nil? (self.parens == true) ? "(#{au})" : au end |
#author_year ⇒ Object
TODO: rename to reflect parens return [String] an author/year string, including parens for the name
133 134 135 136 137 |
# File 'lib/taxonifi/model/name.rb', line 133 def au = return nil if au.nil? (self.parens == true) ? "(#{au})" : au end |
#author_year_string ⇒ Object
Return the author year string.
166 167 168 169 170 |
# File 'lib/taxonifi/model/name.rb', line 166 def au = [, 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)
173 174 175 |
# File 'lib/taxonifi/model/name.rb', line 173 def display_name [nomenclator_name, ].compact.join(" ") end |
#generate_author_year_index ⇒ Object
Generate and return (String) the author year index.
274 275 276 |
# File 'lib/taxonifi/model/name.rb', line 274 def @author_year_index = Taxonifi::Model::AuthorYear.new(people: @authors, year: @year).compact_index end |
#genus_group? ⇒ Boolean
TODO: test Returne True of False based on @rank
286 287 288 |
# File 'lib/taxonifi/model/name.rb', line 286 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(?)
214 215 216 |
# File 'lib/taxonifi/model/name.rb', line 214 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
127 128 129 |
# File 'lib/taxonifi/model/name.rb', line 127 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
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/taxonifi/model/name.rb', line 196 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)
178 179 180 181 182 183 184 185 186 |
# File 'lib/taxonifi/model/name.rb', line 178 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
190 191 192 |
# File 'lib/taxonifi/model/name.rb', line 190 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?
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/taxonifi/model/name.rb', line 235 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.
251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/taxonifi/model/name.rb', line 251 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?
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/taxonifi/model/name.rb', line 220 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
291 292 293 |
# File 'lib/taxonifi/model/name.rb', line 291 def prologify "false" end |
#species_group? ⇒ Boolean
TODO: test Returne True of False based on @rank
280 281 282 |
# File 'lib/taxonifi/model/name.rb', line 280 def species_group? true if @rank == 'species' || @rank == 'subspecies' end |