Class: FeedMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/feed_mapper.rb

Constant Summary collapse

@@find_to_replace =
{ #CommissionJunction
  "//links/link"  => "item",
  "//links/item/link-id" => "item-id",
  "//root/links/item/promotion-start-date" => "startdate",
  "//root/links/item/promotion-end-date" => "enddate",
  "//root/links/item/link-code-html" => "link",
  #ForMeToCoupon
  "//root/item/dealtypes/type" => "dealtype",
  "//root/item/merchantname" => "advertiser-name",
  "//root/item/merchantid"  => "advertiser-id",
  "//root/item/label" => "description",
  "//root/item/couponid" => "item-id"
}

Class Method Summary collapse

Class Method Details

.massage_feed(xml) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/feed_mapper.rb', line 18

def self.massage_feed(xml)

  doc = Nokogiri::XML(xml)
  
  doc.xpath("/").first.children.first.name="root"

  @@find_to_replace.each_pair do |key, value|
    unless doc.xpath(key).first.nil? then 
      doc.xpath(key).each do |child|        
        child.name=(value)
      end
    end
  end
  return doc

end