Sha256: 0ce66d4c2381f72387fa8df162ee6e0d2a2b084cf537c87ce7bbd484b3f28240

Contents?: true

Size: 815 Bytes

Versions: 3

Compression:

Stored size: 815 Bytes

Contents

require 'rpi_marca/helpers'
require 'rpi_marca/publication'
require 'nokogiri'

module RpiMarca
  class Magazine
    include Enumerable

    attr_reader :number, :date

    def initialize(src)
      @source = Nokogiri::XML(src).root

      @number = Helpers.get_attribute_value(@source, 'numero').to_i
      @date = Helpers.parse_date(
        Helpers.get_attribute_value(@source, 'data')
      )
    end

    def each
      if block_given?
        @source.xpath('//processo').each { |el| yield Publication.new(el) }
      else
        to_enum(:each)
      end
    end

    def valid?
      schema = File.join(
        File.dirname(File.expand_path(__FILE__)),
        'magazine.xsd'
      )

      File.open(schema, 'r') do |f|
        Nokogiri::XML::Schema(f).valid?(@source.document)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rpi_marca-0.0.3 lib/rpi_marca/magazine.rb
rpi_marca-0.0.2 lib/rpi_marca/magazine.rb
rpi_marca-0.0.1 lib/rpi_marca/magazine.rb