Module: ProperProperties::Encoding

Defined in:
lib/proper_properties/encoding.rb,
lib/proper_properties/encoding/unicode.rb,
lib/proper_properties/encoding/separators.rb,
lib/proper_properties/encoding/special_chars.rb

Overview

Module to encode and decode

Usage:

encoded = Encoding.encode!("Some text to be encoded")
decoded = Encoding.decode!("Some text to be decoded")

You can disable separate encoding (and decoding) steps, by passing in additional flags:

  • SKIP_SEPARATORS: Do not code the separators (space,:,=)

  • SKIP_UNICODE: Do not code unicode chars

  • SKIP_SPECIAL_CHARS: Do not code newlines, tab stops, …

Defined Under Namespace

Modules: Separators, SpecialChars, Unicode

Constant Summary collapse

SKIP_SEPARATORS =

Flag for skipping separators encodings / decoding

Returns:

  • (Symbol)
:skip_separators
SKIP_UNICODE =

Flag for skipping separators encodings / decoding

Returns:

  • (Symbol)
:skip_unicode
SKIP_SPECIAL_CHARS =

Flag for skipping separators encodings / decoding

Returns:

  • (Symbol)
:skip_special_chars

Class Method Summary collapse

Class Method Details

.decode!(text, *flags) ⇒ String

Decodes a given text in place

Parameters:

  • text (String)
  • *flags (Array)

    Optional flags to skip decoding steps

Returns:

  • (String)

    The decoded text for chaining



48
49
50
51
52
53
# File 'lib/proper_properties/encoding.rb', line 48

def self.decode!(text, *flags)
  Unicode.decode!(text)       unless flags.include?(SKIP_UNICODE)
  Separators.decode!(text)    unless flags.include?(SKIP_SEPARATORS)
  SpecialChars.decode!(text)  unless flags.include?(SKIP_SPECIAL_CHARS)
  text
end

.encode!(text, *flags) ⇒ String

Encode a given text in place

Parameters:

  • text (String)
  • *flags (Array)

    Optional flags to skip encoding steps

Returns:

  • (String)

    The encoded text for chaining



37
38
39
40
41
42
# File 'lib/proper_properties/encoding.rb', line 37

def self.encode!(text, *flags)
  SpecialChars.encode!(text)  unless flags.include?(SKIP_SPECIAL_CHARS)
  Separators.encode!(text)    unless flags.include?(SKIP_SEPARATORS)
  Unicode.encode!(text)       unless flags.include?(SKIP_UNICODE)
  text
end