Class: AmazonReport::Parser
- Inherits:
-
Object
- Object
- AmazonReport::Parser
- Defined in:
- lib/amazon_report/parser.rb
Defined Under Namespace
Classes: BlackCartError
Constant Summary collapse
- @@logger =
Logger.new(nil)
Class Method Summary collapse
Instance Method Summary collapse
- #parse_orders_xml(xml_string) ⇒ Object
- #parse_sales_xml(xml_string) ⇒ Object
- #to_number(string) ⇒ Object
Class Method Details
.logger=(logger) ⇒ Object
10 11 12 |
# File 'lib/amazon_report/parser.rb', line 10 def self.logger=(logger) @@logger = logger end |
Instance Method Details
#parse_orders_xml(xml_string) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/amazon_report/parser.rb', line 32 def parse_orders_xml(xml_string) hash = {} doc = Nokogiri::XML(xml_string) doc.search("Items > Item").each{ |item| asin = item.attributes["ASIN"].value nqty = item.attributes["NQty"].value # その他注文された商品 dqty = item.attributes["DQty"].value # 注文数合計 qty = item.attributes["Qty"].value # 直接リンクによる注文数 clicks = item.attributes["Clicks"].value # クリック数 date = Time.parse(item.attributes["Date"].value) # 日付 tag = item.attributes["Tag"].value hash[asin] = { :nqty => nqty, :dqty => dqty, :qty => qty, :clicks => clicks, } } doc.search("ItemsNoOrders > Item").each{ |item| asin = item.attributes["ASIN"].value clicks = item.attributes["Clicks"].value hash[asin] = { :nqty => "0", :dqty => "0", :qty => "0", :clicks => clicks } } hash end |
#parse_sales_xml(xml_string) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/amazon_report/parser.rb', line 14 def parse_sales_xml(xml_string) hash = {} doc = Nokogiri::XML(xml_string) doc.search("Items > Item").each{ |item| asin = item.attributes["ASIN"].value revenue = item.attributes["Revenue"].value qty = item.attributes["Qty"].value earnings = item.attributes["Earnings"].value date = Time.parse(item.attributes["Date"].value) hash[asin] = { :revenue => revenue, :qty => qty, :earnings => earnings, } } hash end |
#to_number(string) ⇒ Object
63 64 65 |
# File 'lib/amazon_report/parser.rb', line 63 def to_number(string) string.gsub(/,/, "").to_i end |