class BubbleWrap::RSSParser

Attributes

debug[RW]
delegate[RW]
doc[RW]
parser[RW]
parser_error[RW]
source[RW]
state[R]

Public Class Methods

new(input, data=false) click to toggle source
# File motion/rss_parser.rb, line 51
def initialize(input, data=false)
  if data
    data_to_parse = input.respond_to?(:to_data) ? input.to_data : input
    @source = data_to_parse
    @source_type = :data
  else
    url = input.is_a?(NSURL) ? input : NSURL.alloc.initWithString(input)
    @source = url
    @source_type = :url
  end
  self
end

Public Instance Methods

parse(&block) click to toggle source

Starts the parsing and send each parsed item through its block.

Usage:

feed.parse do |item|
  puts item.link
end
# File motion/rss_parser.rb, line 78
def parse(&block)
  @block = block

  if @source_type == :url
    @parser = NSXMLParser.alloc.initWithContentsOfURL(@source)
  else
    @parser = NSXMLParser.alloc.initWithData(@source)
  end

  @parser.shouldProcessNamespaces = true
  @parser.delegate ||= self
  self.state = :initializes
  @parser.parse
end
parserDidEndDocument(parser) click to toggle source

delegate getting called when the parsing is done If a block was set, it will be called on each parsed items

# File motion/rss_parser.rb, line 137
def parserDidEndDocument(parser)
  puts "done parsing" if debug
  self.state = :is_done unless self.state == :errors
end
parserDidStartDocument(parser) click to toggle source

Delegate getting called when parsing starts

# File motion/rss_parser.rb, line 94
def parserDidStartDocument(parser)
  puts "starting parsing.." if debug
  self.state = :parses
end
parserError() click to toggle source
# File motion/rss_parser.rb, line 142
def parserError
  @parser_error || @parser.parserError
end
state=(new_state) click to toggle source
# File motion/rss_parser.rb, line 64
def state=(new_state)
  @state = new_state
  callback_meth = "when_parser_#{new_state}"
  if self.delegate && self.delegate.respond_to?(callback_meth)
    self.delegate.send(callback_meth)
  end
end