Sha256: b21564e82104a849d1364a7f6106906b86694a3626278c98a79d6a7677f94618

Contents?: true

Size: 1.35 KB

Versions: 13

Compression:

Stored size: 1.35 KB

Contents

module Junoser
  module Xsd
    module Base
      attr_reader :xml

      OFFSET = '  '

      def initialize(xml, options={})
        @xml = xml
        @depth = options[:depth] || 0
      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


      private

      def oneliner?
        @oneliner ||= !xml.xpath('./xsd:annotation/xsd:appinfo/flag[text()="oneliner"]').empty?
      end

      def nokeyword?
        @nokeyword ||= !xml.xpath('./xsd:annotation/xsd:appinfo/flag[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

13 entries across 13 versions & 1 rubygems

Version Path
junoser-0.3.12 lib/junoser/xsd/base.rb
junoser-0.3.11 lib/junoser/xsd/base.rb
junoser-0.3.10 lib/junoser/xsd/base.rb
junoser-0.3.9 lib/junoser/xsd/base.rb
junoser-0.3.8 lib/junoser/xsd/base.rb
junoser-0.3.7 lib/junoser/xsd/base.rb
junoser-0.3.6 lib/junoser/xsd/base.rb
junoser-0.3.5 lib/junoser/xsd/base.rb
junoser-0.3.4 lib/junoser/xsd/base.rb
junoser-0.3.3 lib/junoser/xsd/base.rb
junoser-0.3.2 lib/junoser/xsd/base.rb
junoser-0.3.1 lib/junoser/xsd/base.rb
junoser-0.3.0 lib/junoser/xsd/base.rb