Sha256: 20857c3d27624b185491ea3fb57618eebb8405dc3c6eb534cb0ccc62aa6fa654

Contents?: true

Size: 928 Bytes

Versions: 3

Compression:

Stored size: 928 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

3 entries across 3 versions & 2 rubygems

Version Path
rfeedparser-ictv-0.9.931 lib/rfeedparser/better_attributelist.rb
rfeedparser_ictv-0.9.931 lib/rfeedparser/better_attributelist.rb
rfeedparser_ictv-0.9.932 lib/rfeedparser/better_attributelist.rb