Sha256: 76ecbb11677325cfd572e012f938e482ac4dbac0b5c73dc9e02003867fc6607a

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

module Liberic
  module Response
    class Version
      VERSION_NS = 'http://www.elster.de/EricXML/1.0/EricVersion'

      attr_reader :response_xml, :response_dom
      attr_reader :libs

      def initialize(response_xml)
        @response_xml = response_xml
        @response_dom = Nokogiri::XML(@response_xml)

        @libs = @response_dom.xpath('//version:Bibliothek', version: VERSION_NS).map do |lib|
          fields = Hash[
            {file: 'Name',
             product_version: 'Produktversion',
             file_version: 'Dateiversion'}.map do |key, german_field|
              [key, lib.xpath("version:#{german_field}", version: VERSION_NS).text]
            end
          ]

          fields[:name] = fields[:file].split('.').first

          [:product_version, :file_version].each do |version_type|
            fields[version_type] = fields[version_type].split(',').map(&:strip).join('.')
          end
          fields
        end
      end

      def for_library(name)
        (
          @libs.find { |lib| lib[:name] == name } ||
          (raise LibraryNotFound.new("Library #{name} could not be found in this ERiC installation"))
        )[:product_version]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
liberic-1.3.1 lib/liberic/response/version.rb
liberic-1.3.0 lib/liberic/response/version.rb
liberic-1.2.0 lib/liberic/response/version.rb
liberic-1.1.0 lib/liberic/response/version.rb