Class: Peddler::FlatFileParser Private

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Headers
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 }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Headers

#quota, #request_id, #response_context, #timestamp

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.



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

def initialize(res, encoding)
  super(res)
  scrub_body!(encoding)
  extract_content_and_summary
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.



16
17
18
# File 'lib/peddler/flat_file_parser.rb', line 16

def content
  @content
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.



16
17
18
# File 'lib/peddler/flat_file_parser.rb', line 16

def summary
  @summary
end

Instance Method Details

#parse(&blk) ⇒ Object

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.



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

def parse(&blk)
  CSV.parse(content, OPTIONS, &blk) 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.



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

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)


32
33
34
# File 'lib/peddler/flat_file_parser.rb', line 32

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