Class: Taxonifi::Model::Name

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

Overview

A taxonomic name.

Direct Known Subclasses

IcznName

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

Base::ATTRIBUTES

Instance Attribute Summary collapse

Attributes inherited from Base

#id, #properties, #row_number

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 = {}) ⇒ 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(options = {})
  super
  opts = {
    id: nil
  }.merge!(options)

  @parent = nil
  @authors ||= []

  build(@@ATTRIBUTES, opts)
  assign_author_year(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

#authorObject

String, authors as originally read



14
15
16
# File 'lib/taxonifi/model/name.rb', line 14

def author
  @author
end

#author_year_indexObject

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
  @author_year_index
end

#authorsObject

An Array of Taxonifi::Model::Person Optionally parsed/index



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

def authors
  @authors
end

#nameObject

String



8
9
10
# File 'lib/taxonifi/model/name.rb', line 8

def name
  @name
end

#original_description_referenceObject

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

#parensObject

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

#parentObject

A Taxonifi::Model::Name



23
24
25
# File 'lib/taxonifi/model/name.rb', line 23

def parent
  @parent
end

#rankObject

String



11
12
13
# File 'lib/taxonifi/model/name.rb', line 11

def rank
  @rank
end

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
  @related_name
end

#yearObject

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 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_yearObject

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 author_year
  au = author_year_string
  return nil if au.nil?
  (self.parens == true) ? "(#{au})" : au
end

#author_year_stringObject

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 author_year_string
  # Build based on People 

  auth = nil
  if authors.size > 0
    case authors.size
    when 1
      auth = self.author
    when 2 
      auth = authors.map(&:last_name).join(" & ")
    when 2...100
      auth =  authors[0..-1].map(&:last_name).join(", ") + " & " + authors.last.last_name
    end
    # Build based on string
  else
    auth = self.author
  end
  au = [auth, self.year].compact.join(", ")
  return nil if au.size == 0
  au
end

#derive_authors_yearObject

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 derive_authors_year
  add_author_year(author_year_string) 
end

#display_nameObject

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, author_year].compact.join(" ")
end

#generate_author_year_indexObject

Generate and return (String) the author year index.



265
266
267
# File 'lib/taxonifi/model/name.rb', line 265

def generate_author_year_index
  @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

Returns:

  • (Boolean)


277
278
279
# File 'lib/taxonifi/model/name.rb', line 277

def genus_group?
  true if @rank == 'genus' || @rank == 'subgenus'
end

#genus_group_parentObject

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_rankObject

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_stringObject

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_author_year_string
  [name, author_year_string].compact.join(" ")
end

#nomenclator_arrayObject

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_nameObject

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

Returns:

  • (Boolean)


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_styleObject

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

#prologifyObject

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

Returns:

  • (Boolean)


271
272
273
# File 'lib/taxonifi/model/name.rb', line 271

def species_group?
  true if @rank == 'species' || @rank == 'subspecies'
end