Class: Pipe

Inherits:
Object
  • Object
show all
Defined in:
lib/pipe.rb

Constant Summary collapse

VERSION =
'0.1.1'
HEADER =
%q{<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel>}
%q{</channel></rss>}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePipe



24
25
26
# File 'lib/pipe.rb', line 24

def initialize
  @content = ""
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



10
11
12
# File 'lib/pipe.rb', line 10

def content
  @content
end

Class Method Details

.create(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pipe.rb', line 12

def self.create(&block)
  pipe = Pipe.new
  
  if block.arity.zero?
    pipe.instance_eval(&block)
  else
    block.call(pipe)
  end

  HEADER + pipe.content + FOOTER
end

Instance Method Details

#feed(url, filters = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/pipe.rb', line 28

def feed(url,filters={})
  enum = (filters[:combine_with] == :and ? :all? : :any?)

  doc = Hpricot.XML(open(url))

  @content += (doc/:item).select do |item|
    filters.send(enum) { |field,pattern| (item/field).to_s =~ pattern }
  end.to_s
end