Sha256: 65aaa8c2712f95ab1e4cca29206360a3c18aa95aecc42f65be13e74fc45e5428

Contents?: true

Size: 858 Bytes

Versions: 5

Compression:

Stored size: 858 Bytes

Contents

#!/usr/bin/ruby

# Add some helper methods to make AttributeList (all of those damn attrs
# and attrsD used by StrictFeedParser) act more like a Hash.
# NOTE AttributeList is still Read-Only (AFAICT).
# Monkey patching is terrible, and I have an addiction.
module XML
  module SAX
    module AttributeList # in xml/sax.rb
      def [](key)
	getValue(key)
      end

      def each(&blk)
	(0...getLength).each{|pos| yield [getName(pos), getValue(pos)]}
      end

      def each_key(&blk)
	(0...getLength).each{|pos| yield getName(pos) }
      end

      def each_value(&blk)
	(0...getLength).each{|pos| yield getValue(pos) }
      end

      def to_a # Rather use collect? grep for to_a.collect
	l = []
	each{|k,v| l << [k,v]}
	return l
      end

      def to_s
	l = []
	each{|k,v| l << "#{k} => #{v}"}
	"{ "+l.join(", ")+" }"
      end
    end
  end
end


Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rfeedparser-0.9.9 lib/rfeedparser/better_attributelist.rb
rfeedparser-0.9.91 lib/rfeedparser/better_attributelist.rb
rfeedparser-0.9.92 lib/rfeedparser/better_attributelist.rb
rfeedparser-0.9.93 lib/rfeedparser/better_attributelist.rb
rfeedparser-0.9.931 lib/rfeedparser/better_attributelist.rb