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]', ' subsp.', ' 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?
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/utilities/italicize.rb', line 28 def self.taxon_name(string) # Don't use .blank?, anticipate moving out of Rails st = string.dup return nil if st.nil? || st == '' # 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 st = st.gsub(/(#{COMBINATION_INJECTION_REGEX})/, '</i>\1<i>') st = "<i>#{st}</i>". gsub('<i> ', ' <i>'). gsub(')</i>', '</i>)'). gsub('<i></i>', '') st end |