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_stringObject

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 author_string
  auth = nil
  if authors.size > 0 # Build based on People 
    case authors.size
    when 1
      auth = authors.first.last_name # self.author
    when 2 
      auth = authors.map(&:last_name).join(" & ")
    when 3...100
      auth =  authors[0..-1].map(&:last_name).join(", ") + " & " + authors.last.last_name
    end
  else # Build based on string
    auth = self.author
  end
  auth
end

#author_with_parensObject

return [String] an author string, including parens for the name



141
142
143
144
145
# File 'lib/taxonifi/model/name.rb', line 141

def author_with_parens
  au = author_string
  return nil if au.nil?
  (self.parens == true) ? "(#{au})" : au
end

#author_yearObject

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



166
167
168
169
170
# File 'lib/taxonifi/model/name.rb', line 166

def author_year_string
  au = [author_string, 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)



173
174
175
# File 'lib/taxonifi/model/name.rb', line 173

def display_name
  [nomenclator_name, author_year].compact.join(" ")
end

#generate_author_year_indexObject

Generate and return (String) the author year index.



274
275
276
# File 'lib/taxonifi/model/name.rb', line 274

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)


286
287
288
# File 'lib/taxonifi/model/name.rb', line 286

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(?)



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


127
128
129
# File 'lib/taxonifi/model/name.rb', line 127

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


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_nameObject

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

Returns:

  • (Boolean)


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_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.


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

#prologifyObject

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

Returns:

  • (Boolean)


280
281
282
# File 'lib/taxonifi/model/name.rb', line 280

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