Class: Pipe

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

Constant Summary collapse

VERSION =
'0.1.0'
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

Returns a new instance of Pipe.



18
19
20
# File 'lib/pipe.rb', line 18

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
# File 'lib/pipe.rb', line 12

def self.create(&block)
  pipe = Pipe.new
  pipe.instance_eval(&block)
  HEADER + pipe.content + FOOTER
end

Instance Method Details

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



22
23
24
25
26
27
28
# File 'lib/pipe.rb', line 22

def feed(url,filters={})
  doc = Hpricot.XML(open(url))

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