Class: Liberic::Response::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/liberic/response/version.rb

Constant Summary collapse

VERSION_NS =
'http://www.elster.de/EricXML/1.0/EricVersion'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_xml) ⇒ Version


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/liberic/response/version.rb', line 9

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

Instance Attribute Details

#libsObject (readonly)

Returns the value of attribute libs


7
8
9
# File 'lib/liberic/response/version.rb', line 7

def libs
  @libs
end

#response_domObject (readonly)

Returns the value of attribute response_dom


6
7
8
# File 'lib/liberic/response/version.rb', line 6

def response_dom
  @response_dom
end

#response_xmlObject (readonly)

Returns the value of attribute response_xml


6
7
8
# File 'lib/liberic/response/version.rb', line 6

def response_xml
  @response_xml
end

Instance Method Details

#for_library(name) ⇒ Object


30
31
32
33
34
35
# File 'lib/liberic/response/version.rb', line 30

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