Sha256: 99f6bd795938b95b748f4ab0011de382863159e58a9e6a3d0751de6de290a220

Contents?: true

Size: 544 Bytes

Versions: 2

Compression:

Stored size: 544 Bytes

Contents

require 'rexml/document'
require 'uri'

module PRSS
  class Links
    class InvalidXMLError < StandardError; end

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

    attr_reader :xml

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

    def each
      return to_enum unless block_given?

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
prss-0.2.4 lib/prss/links.rb
prss-0.2.3 lib/prss/links.rb