Class: Plist::StreamParser

### Home Classes Methods

### In Files

- lib/plist/parser.rb

### Parent

Object

### Methods

- ::new
- #parse

### Class/Module Index

Quicksearch

- Plist
- Plist::Emit
- Plist::Listener
- Plist::PArray
- Plist::PData
- Plist::PDate
- Plist::PDict
- Plist::PFalse
- Plist::PInteger
- Plist::PKey
- Plist::PList
- Plist::PReal
- Plist::PString
- Plist::PTag
- Plist::PTrue
- Plist::StreamParser

No matching classes.

# Plist::StreamParser

### Constants

COMMENT_END
COMMENT_START
DOCTYPE_PATTERN
TEXT
XMLDECL_PATTERN

### Public Class Methods

new( plist_data_or_file, listener ) click to toggle source

    # File lib/plist/parser.rb, line 63
    def initialize( plist_data_or_file, listener )
      if plist_data_or_file.respond_to? :read
        @xml = plist_data_or_file.read
      elsif File.exists? plist_data_or_file
        @xml = File.read( plist_data_or_file )
      else
        @xml = plist_data_or_file
      end

      @listener = listener
    end

### Public Instance Methods

parse() click to toggle source

    # File lib/plist/parser.rb, line 82
    def parse
      plist_tags = PTag::mappings.keys.join('|')
      start_tag  = /<(#{plist_tags})([^>]*)>/
      end_tag    = /<\/(#{plist_tags})[^>]*>/

      require 'strscan'

      @scanner = StringScanner.new( @xml )
      until @scanner.eos?
        if @scanner.scan(COMMENT_START)
          @scanner.scan(COMMENT_END)
        elsif @scanner.scan(XMLDECL_PATTERN)
        elsif @scanner.scan(DOCTYPE_PATTERN)
        elsif @scanner.scan(start_tag)
          @listener.tag_start(@scanner[1], nil)
          if (@scanner[2] =~ /\/$/)
            @listener.tag_end(@scanner[1])
          end
        elsif @scanner.scan(TEXT)
          @listener.text(@scanner[1])
        elsif @scanner.scan(end_tag)
          @listener.tag_end(@scanner[1])
        else
          raise "Unimplemented element"
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.