class SoapyBing::Ads::Parsers::BulkCsvParser

Attributes

raw[R]

Public Class Methods

new(raw) click to toggle source
# File lib/soapy_bing/ads/parsers/bulk_csv_parser.rb, line 9
def initialize(raw)
  @raw = raw
end

Public Instance Methods

rows() click to toggle source
# File lib/soapy_bing/ads/parsers/bulk_csv_parser.rb, line 13
def rows
  @rows ||= begin
    header, *body = extract_csv_payload
    body.map { |row| header.zip(row).to_h }
  end
end

Private Instance Methods

extract_csv_payload() click to toggle source
# File lib/soapy_bing/ads/parsers/bulk_csv_parser.rb, line 24
def extract_csv_payload
  text = raw.dup
  text.force_encoding(Encoding::UTF_8).encode! unless text.encoding == Encoding::UTF_8
  text.sub!(/^\xEF\xBB\xBF/, '') # cleanup BOM

  CSV.parse(text)
end