Sha256: 41976222e7b27400135c3d6c05165643e54b9303e14eea6f479ef7c18b31062d

Contents?: true

Size: 1.59 KB

Versions: 14

Compression:

Stored size: 1.59 KB

Contents

module Junoser
  module Xsd
    module Base
      attr_reader :xml, :parent

      OFFSET = '  '

      def initialize(xml, options={})
        @xml = xml
        @depth = options[:depth] || 0
        @parent = options[:parent]
      end

      def config
        raise "ERROR: no implementation"
      end

      def children
        @children||= xml.xpath('./*[not(self::xsd:annotation)]')
      end

      def root?
        @depth == 1
      end

      def inspect
        ["#<#{self.class}:0x#{object_id}",
         "xml=#{xml.namespace.prefix}:#{xml.name}" <<
         " attributes=" << Hash[xml.attributes.map {|k, v| [k, v.value] }].to_s <<
         (respond_to?(:label) ? " label=#{label}" : ''),
         "config=[",
         *config.map {|c| c.inspect },
         ']>'].join("\n#{OFFSET*(@depth+1)}")
      end

      def oneliner?
        # don't use "/flag" as xsd manipulation automatically add "xsd:" prefix
        @oneliner ||= !xml.xpath('./xsd:annotation/xsd:appinfo/*[local-name()="flag" and text()="oneliner"]').empty?
      end


      private

      def nokeyword?
        # don't use "/flag" as xsd manipulation automatically add "xsd:" prefix
        @nokeyword ||= !xml.xpath('./xsd:annotation/xsd:appinfo/*[local-name()="flag" and text()="nokeyword"]').empty?
      end

      def has_single_child_of?(klass)
        config.size == 1 && config.first.is_a?(klass)
      end

      def format(header, content=nil, footer=nil)
        str = OFFSET*@depth << header.to_s
        str << "\n" << content if content
        str << "\n" << OFFSET*@depth << footer if footer
        str
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
junoser-0.6.0 lib/junoser/xsd/base.rb
junoser-0.5.6 lib/junoser/xsd/base.rb
junoser-0.5.5 lib/junoser/xsd/base.rb
junoser-0.5.4 lib/junoser/xsd/base.rb
junoser-0.5.3 lib/junoser/xsd/base.rb
junoser-0.5.2 lib/junoser/xsd/base.rb
junoser-0.5.1 lib/junoser/xsd/base.rb
junoser-0.5.0 lib/junoser/xsd/base.rb
junoser-0.4.7 lib/junoser/xsd/base.rb
junoser-0.4.6 lib/junoser/xsd/base.rb
junoser-0.4.5 lib/junoser/xsd/base.rb
junoser-0.4.4 lib/junoser/xsd/base.rb
junoser-0.4.3 lib/junoser/xsd/base.rb
junoser-0.4.2 lib/junoser/xsd/base.rb