Class: Peddler::FlatFileParser Private

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/peddler/flat_file_parser.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

stackoverflow.com/questions/8073920/importing-csv-quoting-error-is-driving-me-nuts

{ col_sep: "\t", quote_char: "\x00", headers: true }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(res, encoding) ⇒ FlatFileParser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FlatFileParser.



13
14
15
16
17
# File 'lib/peddler/flat_file_parser.rb', line 13

def initialize(res, encoding)
  super(res)
  @encoding = encoding
  extract_content
end

Instance Attribute Details

#contentObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/peddler/flat_file_parser.rb', line 11

def content
  @content
end

#encodingObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/peddler/flat_file_parser.rb', line 11

def encoding
  @encoding
end

#summaryObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/peddler/flat_file_parser.rb', line 11

def summary
  @summary
end

Instance Method Details

#parseObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/peddler/flat_file_parser.rb', line 19

def parse
  CSV.parse(scrub_content, OPTIONS) if content
end

#records_countObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
# File 'lib/peddler/flat_file_parser.rb', line 23

def records_count
  summarize if summary
end

#valid?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


27
28
29
# File 'lib/peddler/flat_file_parser.rb', line 27

def valid?
  headers['Content-MD5'] == Digest::MD5.base64digest(body)
end