Sha256: e0235fa370094e7ecfcba83d9dbdb4035ca6dd59ebebac00006c860875170255

Contents?: true

Size: 619 Bytes

Versions: 4

Compression:

Stored size: 619 Bytes

Contents

require 'nokogiri'

module Rocx
  module Parts
    class BasePart
      include ::Nokogiri

      def build_xml
        XML::Builder.new(encoding: "utf-8") { |xml| yield xml }.to_xml
      end

      def build_standalone_xml
        xml = Nokogiri::XML("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>")
        XML::Builder.with(xml) { |xml| yield xml }.to_xml
      end

      def read
        strip_whitespace to_xml
      end

      def to_xml
        raise NotImplementedError
      end

    protected

      def strip_whitespace(xml)
        xml.lines.map(&:strip).join
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rocx-0.7.0 lib/rocx/parts/base_part.rb
rocx-0.6.0 lib/rocx/parts/base_part.rb
rocx-0.5.8 lib/rocx/parts/base_part.rb
rocx-0.5.7 lib/rocx/parts/base_part.rb