module Truty::Conversion
Module with conversion engine for plain text. Converts to HTML. @author Matěj Kašpar Jirásek
Public Instance Methods
Fixes the typography and also converts the string.
@param input [String] Text input. @param conversion [Symbol] Conversion
type (“html” or “none”) @param convert [Array] Array of symbols with features that should be improved (possibilities: all
, hyphens
, quotes
, ellipsis
, dashes
, abbreviations
, prepositions
, numbers
, dates
, characters
, brackets
, multiplication
, units
, widows
) @return [String] Fixed and converted text.
# File lib/truty/conversion.rb, line 16 def convert(input, conversion = :html, lang = :general, convert = [:all]) if !Truty.respond_to? conversion then conversion = :none end Truty.send(conversion, Truty.fix(input, lang, convert)) end
Returns hash with Czech
HTML entities as keys and values as their respective human readable versions.
@return [Hash] Hash with entities.
# File lib/truty/conversion.rb, line 35 def czech_diacritics { "á" => "á", "č" => "č", "ď" => "ď", "é" => "é", "ě" => "ě", "í" => "í", "ň" => "ň", "ó" => "ó", "ř" => "ř", "š" => "š", "ť" => "ť", "ú" => "ú", "ů" => "ů", "ý" => "ý", "ž" => "ž", } end
Escapes string to readable Czech
HTML entities.
@param input [String] Text input. @return [String] Text with HTML entities.
# File lib/truty/conversion.rb, line 59 def czech_html(input) coder = HTMLEntities.new encoded = coder.encode(input, :named, :decimal) czech_diacritics.each { |k, v| encoded.gsub!(k, v) } encoded end
Escapes string to HTML entities.
@param input [String] Text input. @return [String] Text with HTML entities.
# File lib/truty/conversion.rb, line 27 def html(input) coder = HTMLEntities.new coder.encode(input, :named, :decimal) end
Returns the input as it is.
@param input [String] Input for conversion. @return [String] Not changed string from input.
# File lib/truty/conversion.rb, line 70 def none(input) input end