Module: Truty::Conversion
- Included in:
- Truty
- Defined in:
- lib/truty/conversion.rb
Overview
Module with conversion engine for plain text. Converts to HTML.
Instance Method Summary collapse
-
#convert(input, conversion = :html, lang = :general, convert = [:all]) ⇒ String
Fixes the typography and also converts the string.
-
#czech_diacritics ⇒ Hash
Returns hash with Czech HTML entities as keys and values as their respective human readable versions.
-
#czech_html(input) ⇒ String
Escapes string to readable Czech HTML entities.
-
#html(input) ⇒ String
Escapes string to HTML entities.
-
#none(input) ⇒ String
Returns the input as it is.
Instance Method Details
#convert(input, conversion = :html, lang = :general, convert = [:all]) ⇒ String
Fixes the typography and also converts the string.
16 17 18 19 20 21 |
# 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 |
#czech_diacritics ⇒ Hash
Returns hash with Czech HTML entities as keys and values as their respective human readable versions.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/truty/conversion.rb', line 35 def czech_diacritics { "á" => "á", "č" => "č", "ď" => "ď", "é" => "é", "ě" => "ě", "í" => "í", "ň" => "ň", "ó" => "ó", "ř" => "ř", "š" => "š", "ť" => "ť", "ú" => "ú", "ů" => "ů", "ý" => "ý", "ž" => "ž", } end |
#czech_html(input) ⇒ String
Escapes string to readable Czech HTML entities.
59 60 61 62 63 64 |
# 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 |
#html(input) ⇒ String
Escapes string to HTML entities.
27 28 29 30 |
# File 'lib/truty/conversion.rb', line 27 def html(input) coder = HTMLEntities.new coder.encode(input, :named, :decimal) end |
#none(input) ⇒ String
Returns the input as it is.
70 71 72 |
# File 'lib/truty/conversion.rb', line 70 def none(input) input end |