Sha256: 41dc8cf0126763902313ee9d2de4bad4b1f6cd1a9c6d6121cd968e5b8ab61bf4

Contents?: true

Size: 938 Bytes

Versions: 6

Compression:

Stored size: 938 Bytes

Contents

module SAXMachine
  class SAXConfig
    
    class ElementConfig
      attr_reader :name
      
      def initialize(name, options)
        @name = name.to_s
        
        if options.has_key?(:with)
          # for faster comparisons later
          @with = options[:with].to_a.flatten.collect {|o| o.to_s}
        else
          @with = nil
        end
        
        if options.has_key?(:value)
          @value = options[:value].to_s
        else
          @value = nil
        end
        
        @as = options[:as]
      end

      def value_from_attrs(attrs)
        attrs[attrs.index(@value) + 1]
      end
      
      def setter
        "#{@as}="
      end
      
      def attrs_match?(attrs)
        if @with
          @with == (@with & attrs)
        else
          true
        end
      end
      
      def has_value_and_attrs_match?(attrs)
        !@value.nil? && attrs_match?(attrs)
      end
    end
    
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ealdent-sax-machine-0.0.4 lib/sax-machine/sax_element_config.rb
ealdent-sax-machine-0.0.7 lib/sax-machine/sax_element_config.rb
pauldix-sax-machine-0.0.4 lib/sax-machine/sax_element_config.rb
pauldix-sax-machine-0.0.5 lib/sax-machine/sax_element_config.rb
pauldix-sax-machine-0.0.6 lib/sax-machine/sax_element_config.rb
pauldix-sax-machine-0.0.7 lib/sax-machine/sax_element_config.rb