Module: Utilities::Italicize
- Defined in:
- lib/utilities/italicize.rb
Constant Summary collapse
- COMBINATION_INJECTIONS =
Used to italicize strings, whitespace (presently) matters Ultimately turn into Tokens to better handle whitespace
[ ' (', ') ', # no trailing whitespace as it could be terminating in case of subgenus? ' [sic]', ' var.', ' subvar.', ' f.', ' subf.', ' sect.', # not covered in original combination ' ser.', # not covered in original combination 'GENUS NOT SPECIFIED', 'SPECIES NOT SPECIFIED', '[', ']', '† ', # fossil dagger ' ×', # hybrid × # 'Candidatus' ? ].freeze
- COMBINATION_INJECTION_REGEX =
COMBINATION_INJECTIONS.collect{|a| Regexp.escape(a) }.join('|').freeze
Class Method Summary collapse
Class Method Details
.taxon_name(string) ⇒ String?
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/utilities/italicize.rb', line 27 def self.taxon_name(string) # Don't use .blank?, anticipate moving out of Rails return nil if string.nil? || string == '' # May need to revert to this 1:1 form if we find that an individual COMBINATION_INJECTS element are found > 1 per name # TaxonName::COMBINATION_INJECTIONS.collect{|a| Regexp.escape(a) }.each do |r| # string.gsub!(/(#{r})/, '</i>\1<i>') # end string.gsub!(/(#{COMBINATION_INJECTION_REGEX})/, '</i>\1<i>') string = "<i>#{string}</i>" string.gsub!('<i> ', ' <i>') string.gsub!('<i></i>', '') string end |