Class: Taxon

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/taxon.rb

Direct Known Subclasses

Family, Genus, Species, Subfamily, Subgenus, Subspecies, Tribe

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) find_genus_group_by_name(name)



75
76
77
78
79
# File 'app/models/taxon.rb', line 75

def self.find_genus_group_by_name name
  query = where ['taxa.name = ? AND taxa.type IN (?)', name, ['Genus', 'Subgenus']]
  return unless query.count == 1
  query.first
end

+ (Object) find_name(name, search_type = 'matching')



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/taxon.rb', line 55

def self.find_name name, search_type = 'matching'
  query = ordered_by_name
  names = name.split ' '
  if names.size > 1
    query = query.joins 'JOIN taxa genera ON genera.id = taxa.genus_id'
    query = query.where ['genera.name = ?', names.first]
    name = names.second
  end
  types_sought = ['Subfamily', 'Tribe', 'Genus', 'Species']
  case search_type
  when 'matching'
    query = query.where ['taxa.name = ? AND taxa.type IN (?)', name, types_sought]
  when 'beginning with'
    query = query.where ['taxa.name LIKE ? AND taxa.type IN (?)', name + '%', types_sought]
  when 'containing'
    query = query.where ['taxa.name LIKE ? AND taxa.type IN (?)', '%' + name + '%', types_sought]
  end
  query.all
end

+ (Object) get_statistics(ranks)



94
95
96
97
98
99
100
101
# File 'app/models/taxon.rb', line 94

def self.get_statistics ranks
  statistics = {}
  ranks.each do |klass, rank|
    count = klass.count :group => [:fossil, :status]
    massage_count count, rank, statistics
  end
  statistics
end

+ (Object) massage_count(count, rank, statistics)



103
104
105
106
107
108
109
110
111
# File 'app/models/taxon.rb', line 103

def self.massage_count count, rank, statistics
  count.keys.each do |fossil, status|
    value = count[[fossil, status]]
    extant_or_fossil = fossil ? :fossil : :extant
    statistics[extant_or_fossil] ||= {}
    statistics[extant_or_fossil][rank] ||= {}
    statistics[extant_or_fossil][rank][status] = value
  end
end

+ (Object) statistics



81
82
83
# File 'app/models/taxon.rb', line 81

def self.statistics
  get_statistics [[Subfamily, :subfamilies], [Genus, :genera], [Species, :species], [Subspecies, :subspecies]]
end

Instance Method Details

- (Boolean) available?

Returns:

  • (Boolean)


21
# File 'app/models/taxon.rb', line 21

def available?;       !unavailable? end

- (Object) children

Raises:

  • (NotImplementedError)


33
34
35
# File 'app/models/taxon.rb', line 33

def children
  raise NotImplementedError
end

- (Object) convert_asterisks_to_daggers!



113
114
115
# File 'app/models/taxon.rb', line 113

def convert_asterisks_to_daggers!
  update_attribute :taxonomic_history, taxonomic_history.convert_asterisks_to_daggers if taxonomic_history?
end

- (Object) current_valid_name



45
46
47
48
49
# File 'app/models/taxon.rb', line 45

def current_valid_name
  target = self
  target = target.synonym_of while target.synonym_of
  target.name
end

- (Boolean) excluded?

Returns:

  • (Boolean)


27
# File 'app/models/taxon.rb', line 27

def excluded?;        status == 'excluded' end

- (Object) full_name



51
52
53
# File 'app/models/taxon.rb', line 51

def full_name
  name
end

- (Object) get_statistics(ranks)



85
86
87
88
89
90
91
92
# File 'app/models/taxon.rb', line 85

def get_statistics ranks
  statistics = {}
  ranks.each do |rank|
    count = send(rank).count :group => [:fossil, :status]
    self.class.massage_count count, rank, statistics
  end
  statistics
end

- (Boolean) homonym?

Returns:

  • (Boolean)


25
# File 'app/models/taxon.rb', line 25

def homonym?;         status == 'homonym' end

- (Boolean) homonym_replaced_by?(taxon)

Returns:

  • (Boolean)


41
42
43
# File 'app/models/taxon.rb', line 41

def homonym_replaced_by? taxon
  homonym_replaced_by == taxon
end

- (Boolean) incertae_sedis_in?(rank)

Returns:

  • (Boolean)


117
118
119
# File 'app/models/taxon.rb', line 117

def incertae_sedis_in? rank
  incertae_sedis_in == rank
end

- (Boolean) invalid?

Returns:

  • (Boolean)


22
# File 'app/models/taxon.rb', line 22

def invalid?;         status != 'valid' end

- (Object) rank



29
30
31
# File 'app/models/taxon.rb', line 29

def rank
  Rank[self].to_s
end

- (Boolean) synonym?

Returns:

  • (Boolean)


24
# File 'app/models/taxon.rb', line 24

def synonym?;         status == 'synonym' end

- (Boolean) synonym_of?(taxon)

Returns:

  • (Boolean)


37
38
39
# File 'app/models/taxon.rb', line 37

def synonym_of? taxon
  synonym_of == taxon
end

- (Boolean) unavailable?

Returns:

  • (Boolean)


20
# File 'app/models/taxon.rb', line 20

def unavailable?;     status == 'unavailable' end

- (Boolean) unidentifiable?

Returns:

  • (Boolean)


23
# File 'app/models/taxon.rb', line 23

def unidentifiable?;  status == 'unidentifiable' end

- (Boolean) unresolved_homonym?

Returns:

  • (Boolean)


26
# File 'app/models/taxon.rb', line 26

def unresolved_homonym?;status == 'unresolved homonym' end