class SoapyBing::Ads::Parsers::ReportCsvParser
Constants
- CSV_PAYLOAD_OFFSET_BACK
- CSV_PAYLOAD_OFFSET_FRONT
Attributes
raw[R]
Public Class Methods
new(raw)
click to toggle source
# File lib/soapy_bing/ads/parsers/report_csv_parser.rb, line 14 def initialize(raw) @raw = raw end
Public Instance Methods
rows()
click to toggle source
# File lib/soapy_bing/ads/parsers/report_csv_parser.rb, line 18 def rows @rows ||= begin header, *body = extract_csv_payload raise FormatError if body.size != payload_rows_number 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/report_csv_parser.rb, line 30 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_rows = CSV.parse(text) csv_rows[CSV_PAYLOAD_OFFSET_FRONT...-CSV_PAYLOAD_OFFSET_BACK] end
payload_rows_number()
click to toggle source
# File lib/soapy_bing/ads/parsers/report_csv_parser.rb, line 39 def payload_rows_number raw.match(/"Rows: (\d+)"/)[1].to_i end