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



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'motion/rss_parser.rb', line 49

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.state = :initializes
  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



98
99
100
# File 'motion/rss_parser.rb', line 98

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


77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'motion/rss_parser.rb', line 77

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
  @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



135
136
137
138
# File 'motion/rss_parser.rb', line 135

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



92
93
94
95
# File 'motion/rss_parser.rb', line 92

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

#parserErrorObject



140
141
142
# File 'motion/rss_parser.rb', line 140

def parserError
  @parser_error || @parser.parserError
end