Class: BubbleWrap::RSSParser

Inherits:
Object
  • Object
show all
Defined in:
motion/rss_parser.rb

Defined Under Namespace

Classes: RSSItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, data = false) ⇒ RSSParser

Returns a new instance of RSSParser.



51
52
53
54
55
56
57
58
59
60
61
62
# 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

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



25
26
27
# File 'motion/rss_parser.rb', line 25

def debug
  @debug
end

#delegateObject

Returns the value of attribute delegate.



25
26
27
# File 'motion/rss_parser.rb', line 25

def delegate
  @delegate
end

#docObject

Returns the value of attribute doc.



25
26
27
# File 'motion/rss_parser.rb', line 25

def doc
  @doc
end

#parser(parser, parseErrorOccurred: parse_error) ⇒ Object

method called when the parser encounters an error error can be retrieved with parserError



100
101
102
# File 'motion/rss_parser.rb', line 100

def parser
  @parser
end

#parser_errorObject

Returns the value of attribute parser_error.



25
26
27
# File 'motion/rss_parser.rb', line 25

def parser_error
  @parser_error
end

#sourceObject

Returns the value of attribute source.



25
26
27
# File 'motion/rss_parser.rb', line 25

def source
  @source
end

#stateObject

Returns the value of attribute state.



26
27
28
# File 'motion/rss_parser.rb', line 26

def state
  @state
end

Instance Method Details

#parse(&block) ⇒ Object

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

Usage:

feed.parse do |item|
  puts item.link
end


78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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) ⇒ Object

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



137
138
139
140
# 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) ⇒ Object

Delegate getting called when parsing starts



94
95
96
97
# File 'motion/rss_parser.rb', line 94

def parserDidStartDocument(parser)
  puts "starting parsing.." if debug
  self.state = :parses
end

#parserErrorObject



142
143
144
# File 'motion/rss_parser.rb', line 142

def parserError
  @parser_error || @parser.parserError
end