Module: Truty::Conversion

Included in:
Truty
Defined in:
lib/truty/conversion.rb

Overview

Module with conversion engine for plain text. Converts to HTML.

Author:

  • Matěj Kašpar Jirásek

Instance Method Summary collapse

Instance Method Details

#convert(input, conversion = :html, lang = :general) ⇒ String

Fixes the typography and also converts the string.

Parameters:

  • input (String)

    Text input.

  • conversion (Symbol) (defaults to: :html)

    Coversion type (“html” or “none”)

Returns:

  • (String)

    Fixed and converted text.



15
16
17
18
19
20
# File 'lib/truty/conversion.rb', line 15

def convert(input, conversion = :html, lang = :general)
  if !Truty.respond_to? conversion then
    conversion = :none
  end
  Truty.send(conversion, Truty.fix(input, lang))
end

#html(input) ⇒ String

Escapes string to HTML entities.

Parameters:

  • input (String)

    Text input.

Returns:

  • (String)

    Text with HTML entities.



26
27
28
29
# File 'lib/truty/conversion.rb', line 26

def html(input)
  coder = HTMLEntities.new
  coder.encode(input, :named, :decimal)
end

#none(input) ⇒ String

Returns the input as it is.

Parameters:

  • input (String)

    Input for conversion.

Returns:

  • (String)

    Not changed string from input.



35
36
37
# File 'lib/truty/conversion.rb', line 35

def none(input)
  input
end