Sha256: 50bea598913d7e95e51b2ab95ba6c53da57974501a9913ef2ebfcf5df3878e58

Contents?: true

Size: 806 Bytes

Versions: 3

Compression:

Stored size: 806 Bytes

Contents

require 'forwardable'

module ONIX
  # super class for some simplified ONIX::Product wrappers
  class SimpleProduct

    def initialize(product = nil)
      @product = product || ::ONIX::Product.new
    end

    class << self
      
      include Forwardable

      def from_xml(xml)
        self.new(::ONIX::Product.from_xml(xml))
      end

      def parse_file(filename)
        self.new(::ONIX::Product.parse(File.read(filename)))
      end

      def parse(xml)
        self.new(::ONIX::Product.parse(xml))
      end
    
      protected

      def delegate(*args)
        def_delegators :@product, *args
      end
    end

    def product
      @product
    end

    def to_xml
      product.to_xml
    end

    # TODO: add method missing magic to proxy through to the underlying product?

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
onix-0.5.0 lib/onix/simple_product.rb
onix-0.5.1 lib/onix/simple_product.rb
onix-0.6.0 lib/onix/simple_product.rb