Class: Formatters::CatalogFormatter
- Inherits:
-
Object
- Object
- Formatters::CatalogFormatter
- Extended by:
- ActionView::Helpers::NumberHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, ERB::Util, Formatter
- Defined in:
- lib/formatters/catalog_formatter.rb
Class Method Summary (collapse)
- + (Object) css_classes_for_rank(taxon)
- + (Object) format_rank_statistics(statistics, rank, include_invalid)
- + (Object) format_rank_status_count(rank, status, count, label_statuses = true)
- + (Object) format_reference_document_link(reference, user)
- + (Object) format_statistics(statistics, options = {})
- + (Object) format_taxon_statistics(taxon, options = {})
- + (Object) format_taxonomic_history(taxon)
- + (Object) format_taxonomic_history_with_statistics(taxon, options = {})
- + (Object) fossil(name, is_fossil)
- + (Object) ordered_statuses
- + (Object) pluralize_with_delimiters(count, word, plural = nil)
- + (Object) status_labels
- + (Object) status_plural(status)
- + (Object) taxon_label_and_css_classes(taxon, options = {})
Class Method Details
+ (Object) css_classes_for_rank(taxon)
114 115 116 |
# File 'lib/formatters/catalog_formatter.rb', line 114 def self.css_classes_for_rank taxon [taxon.type.downcase, 'taxon'] end |
+ (Object) format_rank_statistics(statistics, rank, include_invalid)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/formatters/catalog_formatter.rb', line 63 def self.format_rank_statistics statistics, rank, include_invalid statistics = statistics[rank] return unless statistics string = '' if statistics['valid'] string << format_rank_status_count(rank, 'valid', statistics['valid'], include_invalid) statistics.delete 'valid' end return string unless include_invalid status_strings = statistics.keys.sort_by do |key| ordered_statuses.index key end.inject([]) do |status_strings, status| status_strings << format_rank_status_count(:genera, status, statistics[status]) end if status_strings.present? string << ' ' if string.present? string << "(#{status_strings.join(', ')})" end string.present? && string end |
+ (Object) format_rank_status_count(rank, status, count, label_statuses = true)
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/formatters/catalog_formatter.rb', line 90 def self.format_rank_status_count rank, status, count, label_statuses = true rank = :subfamily if rank == :subfamilies and count == 1 rank = :genus if rank == :genera and count == 1 if label_statuses count_and_status = pluralize_with_delimiters count, status, status == 'valid' ? status : status_plural(status) else count_and_status = number_with_delimiter count end string = count_and_status string << " #{rank.to_s}" if status == 'valid' string end |
+ (Object) format_reference_document_link(reference, user)
125 126 127 |
# File 'lib/formatters/catalog_formatter.rb', line 125 def self.format_reference_document_link reference, user "<a class=\"document_link\" target=\"_blank\" href=\"#{reference.url}\">PDF</a>".html_safe if reference.downloadable_by? user end |
+ (Object) format_statistics(statistics, options = {})
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 |
# File 'lib/formatters/catalog_formatter.rb', line 32 def self.format_statistics statistics, = {} .reverse_merge! :include_invalid => true, :include_fossil => true return '' unless statistics && statistics.present? strings = [:extant, :fossil].inject({}) do |strings, extant_or_fossil| extant_or_fossil_statistics = statistics[extant_or_fossil] if extant_or_fossil_statistics string = [:subfamilies, :genera, :species, :subspecies].inject([]) do |rank_strings, rank| string = format_rank_statistics(extant_or_fossil_statistics, rank, [:include_invalid]) rank_strings << string if string.present? rank_strings end.join ', ' strings[extant_or_fossil] = string end strings end strings = if strings[:extant] && strings[:fossil] && [:include_fossil] strings[:extant].insert 0, 'Extant: ' strings[:fossil].insert 0, 'Fossil: ' [strings[:extant], strings[:fossil]] elsif strings[:extant] [strings[:extant]] elsif [:include_fossil] ['Fossil: ' + strings[:fossil]] else [] end strings.map do |string| content_tag('p', string, :class => 'taxon_statistics') end.join end |
+ (Object) format_taxon_statistics(taxon, options = {})
26 27 28 29 30 |
# File 'lib/formatters/catalog_formatter.rb', line 26 def self.format_taxon_statistics taxon, = {} statistics = taxon.statistics return '' unless statistics format_statistics statistics, end |
+ (Object) format_taxonomic_history(taxon)
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/formatters/catalog_formatter.rb', line 10 def self.format_taxonomic_history taxon string = taxon.taxonomic_history homonym_replaced = taxon.homonym_replaced if homonym_replaced label_and_classes = taxon_label_and_css_classes taxon, :uppercase => true span = content_tag('span', label_and_classes[:label], :class => label_and_classes[:css_classes]) string << %{<p class="taxon_subsection_header">Homonym replaced by #{span}</p>} string << %{<div id="#{homonym_replaced.id}">#{homonym_replaced.taxonomic_history}</div>} end string.html_safe if string end |
+ (Object) format_taxonomic_history_with_statistics(taxon, options = {})
22 23 24 |
# File 'lib/formatters/catalog_formatter.rb', line 22 def self.format_taxonomic_history_with_statistics taxon, = {} format_taxon_statistics(taxon, ) + format_taxonomic_history(taxon) end |
+ (Object) fossil(name, is_fossil)
118 119 120 121 122 123 |
# File 'lib/formatters/catalog_formatter.rb', line 118 def self.fossil name, is_fossil string = '' string << '†' if is_fossil string << h(name) string.html_safe end |
+ (Object) ordered_statuses
148 149 150 |
# File 'lib/formatters/catalog_formatter.rb', line 148 def self.ordered_statuses status_labels.keys end |
+ (Object) pluralize_with_delimiters(count, word, plural = nil)
152 153 154 155 156 157 |
# File 'lib/formatters/catalog_formatter.rb', line 152 def self.pluralize_with_delimiters count, word, plural = nil if count != 1 word = plural ? plural : word.pluralize end "#{number_with_delimiter(count)} #{word}" end |
+ (Object) status_labels
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/formatters/catalog_formatter.rb', line 133 def self.status_labels @status_labels || begin @status_labels = ActiveSupport::OrderedHash.new @status_labels['synonym'] = {:singular => 'synonym', :plural => 'synonyms'} @status_labels['homonym'] = {:singular => 'homonym', :plural => 'homonyms'} @status_labels['unavailable'] = {:singular => 'unavailable', :plural => 'unavailable'} @status_labels['unidentifiable'] = {:singular => 'unidentifiable', :plural => 'unidentifiable'} @status_labels['excluded'] = {:singular => 'excluded', :plural => 'excluded'} @status_labels['unresolved homonym'] = {:singular => 'unresolved homonym', :plural => 'unresolved homonyms'} @status_labels['recombined'] = {:singular => 'transferred out of this genus', :plural => 'transferred out of this genus'} @status_labels['nomen nudum'] = {:singular => 'nomen nudum', :plural => 'nomina nuda'} @status_labels end end |
+ (Object) status_plural(status)
129 130 131 |
# File 'lib/formatters/catalog_formatter.rb', line 129 def self.status_plural status status_labels[status][:plural] end |
+ (Object) taxon_label_and_css_classes(taxon, options = {})
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/formatters/catalog_formatter.rb', line 103 def self.taxon_label_and_css_classes taxon, = {} fossil_symbol = taxon.fossil? ? "†" : '' css_classes = css_classes_for_rank taxon css_classes << taxon.status.gsub(/ /, '_') css_classes << 'selected' if [:selected] name = taxon.name.dup name.upcase! if [:uppercase] label = fossil_symbol + h(name) {:label => label.html_safe, :css_classes => css_classes_for_taxon(taxon, [:selected])} end |