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.



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

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.



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

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.



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

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.



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

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.



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

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



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

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)


30
31
32
# File 'lib/peddler/flat_file_parser.rb', line 30

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