Class: PRSS::Links

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

Defined Under Namespace

Classes: InvalidXMLError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Links

Returns a new instance of Links.



8
9
10
11
12
# File 'lib/prss/links.rb', line 8

def initialize(xml)
  @xml = ::REXML::Document.new(xml)
rescue REXML::ParseException
  raise InvalidXMLError
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



14
15
16
# File 'lib/prss/links.rb', line 14

def xml
  @xml
end

Instance Method Details

#eachObject



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

def each
  return to_enum unless block_given?

  links.each do |link|
    yield URI(link.text.strip)
  end
end


16
17
18
19
20
# File 'lib/prss/links.rb', line 16

def links
  xml.elements.to_a('//item/link').tap do |links|
    puts "Found #{links.size} links"
  end
end