Module: AdjustN::NewlineChar

Defined in:
lib/adjustn/newlinechar.rb

Defined Under Namespace

Classes: Pair

Constant Summary collapse

AUTONYMS =
{
  cr: :cr,
  lf: :lf,
  crlf: :crlf,
  mac: :cr,
  unix: :lf,
  win: :crlf,
  dos: :crlf
}.freeze
LF =
"\x0a"
CR =
"\x0d"
CRLF =
(CR + LF)
PAIRS =
{
  lf: Pair.new(/#{CRLF}|#{CR}/, LF).freeze,
  cr: Pair.new(/#{CRLF}|#{LF}/, CR).freeze,
  crlf: Pair.new(/(?<!#{CR})#{LF}|#{CR}(?!#{LF})/, CRLF).freeze
}.freeze

Class Method Summary collapse

Class Method Details

.autonym(str) ⇒ Symbol

Returns :cr, :lf, :crlf.

Parameters:

  • str (String)

Returns:

  • (Symbol)

    :cr, :lf, :crlf



33
34
35
36
37
38
39
# File 'lib/adjustn/newlinechar.rb', line 33

def autonym(str)
  if /\A(cr|lf|crlf|mac|unix|win|dos)\z/i.match?(str)
    AUTONYMS.fetch(str.downcase.to_sym)
  else
    raise TypeError
  end
end