Module Atom::Parsers
In: lib/atom/element.rb

Methods

Public Instance methods

adds a parser that calls the given block for a single element that matches the given name and namespace (if it exists)

[Source]

# File lib/atom/element.rb, line 65
    def on_parse name_pair, &block
      uri, name = name_pair
      @on_parse ||= []

      process = lambda do |e,x|
        el = e.get_elem(x, uri, name)

        if el
          block.call e, el

          e.extensions.delete_if do |c|
            c.namespace == uri and c.name == name.to_s
          end
        end
      end

      @on_parse << process
    end

adds a parser that calls the given block for the attribute that matches the given name (if it exists)

[Source]

# File lib/atom/element.rb, line 86
    def on_parse_attr name_pair, &block
      uri, name = name_pair
      @on_parse ||= []

      process = lambda do |e,x|
        x = e.get_atom_attrb(x, name)

        if x
          block.call e, x

          e.extensions.attributes.delete name.to_s
        end
      end

      @on_parse << process
    end

adds a parser that calls the given block for all elements that match the given name and namespace

[Source]

# File lib/atom/element.rb, line 105
    def on_parse_many name_pair, &block
      uri, name = name_pair
      @on_parse ||= []

      process = lambda do |e,x|
        els = e.get_elems(x, uri, name)

        unless els.empty?
          block.call e, els

          els.each do |el|
            e.extensions.delete_if { |c| c.namespace == uri and c.name == name.to_s }
          end
        end
      end

      @on_parse << process
    end

adds a parser that calls the given block for this element

[Source]

# File lib/atom/element.rb, line 125
    def on_parse_root &block
      @on_parse ||= []

      process = lambda do |e,x|
        block.call e, x

        x.elements.each do |el|
          e.extensions.clear
        end
      end

      @on_parse << process
    end

parses the text content of an element named ‘name’ into an attribute on this Element named ‘name‘

[Source]

# File lib/atom/element.rb, line 141
    def parse_plain uri, name
      self.on_parse [uri, name] do |e,x|
        e.set(name, x.text)
      end
    end

[Validate]