Module: Taxt

Defined in:
lib/taxt.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) decode(taxt, user = nil)



8
9
10
11
12
13
# File 'lib/taxt.rb', line 8

def self.decode taxt, user = nil
  return '' unless taxt
  taxt.gsub /{ref (\d+)}/ do |ref|
    Formatters::ReferenceFormatter.format_inline_citation(Reference.find($1), user) rescue ref
  end.html_safe
end

+ (Object) encode_reference(reference)



20
21
22
# File 'lib/taxt.rb', line 20

def self.encode_reference reference
  "{ref #{reference.id}}"
end

+ (Object) encode_taxon_name(name, rank, data = {})



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/taxt.rb', line 24

def self.encode_taxon_name name, rank, data = {}
  name = name.dup
  if data[:suborder_name]
    return "#{Formatters::CatalogFormatter.fossil(name, data[:fossil])} (#{data[:suborder_name]})"
  end

  if rank == :species_group_epithet
    string = '<i>'.html_safe
    string << Formatters::CatalogFormatter.fossil(name, data[:fossil])
    string << '</i>'.html_safe
    return string
  end

  if data[:genus_abbreviation]
    string = '<i>'.html_safe
    string << Formatters::CatalogFormatter.fossil(data[:genus_abbreviation], data[:fossil])
    if data[:species_epithet]
      string << ' ' << data[:species_epithet]
    elsif data[:subgenus_epithet]
      string << ' (' << data[:subgenus_epithet] << ')'
    else raise
    end
    string << '</i>'.html_safe
    return string
  end

  italicize = [:collective_group, :genus].include? rank

  if rank == :genus && data[:species_epithet]
    if data [:subgenus_epithet]
      name += " (#{data[:subgenus_epithet]})"
    end
    name += ' ' + data[:species_epithet]
  end

  output = ''
  output << '<i>' if italicize
  output << Formatters::CatalogFormatter.fossil(name, data[:fossil])
  output << '?' if data[:questionable]
  output << '</i>' if italicize

  output
end

+ (Object) encode_unparseable(string)



16
17
18
# File 'lib/taxt.rb', line 16

def self.encode_unparseable string
  "{? #{string}}"
end

+ (Object) to_string(taxt, user)



4
5
6
# File 'lib/taxt.rb', line 4

def self.to_string taxt, user
  decode taxt, user
end