Class: Csvlint::Validator::LineCSV

Inherits:
CSV
  • Object
show all
Defined in:
lib/csvlint/validate.rb

Constant Summary collapse

ENCODE_RE =
Hash.new do |h,str|
  h[str] = Regexp.new(str)
end
ENCODE_STR =
Hash.new do |h,encoding_name|
  h[encoding_name] = Hash.new do |h,chunks|
    h[chunks] = chunks.map { |chunk| chunk.encode(encoding_name) }.join('')
  end
end
ESCAPE_RE =
Hash.new do |h,re_chars|
  h[re_chars] = Hash.new do |h,re_esc|
    h[re_esc] = Hash.new do |h,str|
      h[str] = str.gsub(re_chars) {|c| re_esc + c}
    end
  end
end

Instance Method Summary collapse

Instance Method Details

#encode_re(*chunks) ⇒ Object

Optimization: Memoize ‘encode_re`.



25
26
27
# File 'lib/csvlint/validate.rb', line 25

def encode_re(*chunks)
  ENCODE_RE[encode_str(*chunks)]
end

#encode_str(*chunks) ⇒ Object

Optimization: Memoize ‘encode_str`.



31
32
33
# File 'lib/csvlint/validate.rb', line 31

def encode_str(*chunks)
  ENCODE_STR[@encoding.name][chunks]
end

#escape_re(str) ⇒ Object

Optimization: Memoize ‘escape_re`.



37
38
39
# File 'lib/csvlint/validate.rb', line 37

def escape_re(str)
  ESCAPE_RE[@re_chars][@re_esc][str]
end

#init_converters(options, field_name = :converters) ⇒ Object

Optimization: Disable the CSV library’s converters feature.



43
44
45
46
47
48
# File 'lib/csvlint/validate.rb', line 43

def init_converters(options, field_name = :converters)
  @converters = []
  @header_converters = []
  options.delete(:unconverted_fields)
  options.delete(field_name)
end