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".freeze
CR =
"\x0d".freeze
CRLF =
(CR + LF).freeze
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


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

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