Class: Saxon::Version::Library

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/saxon/version/library.rb

Overview

The version of the underlying Saxon library, which we need to discover at runtime based on what version is on the Classpath

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, edition) ⇒ Library

Returns a new instance of Library.

Parameters:

  • version (String)

    the version string

  • components (Array<Integer>)

    the version components separated

  • edition (String, Symbol)

    the name of the Saxon edition (e.g. :he, ‘HE’)



30
31
32
33
34
# File 'lib/saxon/version/library.rb', line 30

def initialize(version, edition)
  @version = version.dup.freeze
  @components = version.split('.').map { |n| Integer(n, 10) }
  @edition = edition.downcase.to_sym
end

Instance Attribute Details

#componentsString (readonly)

Returns the version components (e.g. [9, 9, 1, 6], [10, 0]).

Returns:

  • (String)

    the version components (e.g. [9, 9, 1, 6], [10, 0])



23
24
25
# File 'lib/saxon/version/library.rb', line 23

def components
  @components
end

#editionSymbol (readonly)

Returns the edition (:he, :pe, or :ee).

Returns:

  • (Symbol)

    the edition (:he, :pe, or :ee)



25
26
27
# File 'lib/saxon/version/library.rb', line 25

def edition
  @edition
end

#versionString (readonly)

Returns the version string (e.g. ‘9.9.1.6’, ‘10.0’).

Returns:

  • (String)

    the version string (e.g. ‘9.9.1.6’, ‘10.0’)



21
22
23
# File 'lib/saxon/version/library.rb', line 21

def version
  @version
end

Class Method Details

.loaded_versionSaxon::Version::Library

The loaded version of the Saxon Java library

Returns:



11
12
13
14
15
16
# File 'lib/saxon/version/library.rb', line 11

def self.loaded_version
  Saxon::Loader.load!

  sv = Java::net.sf.saxon.Version
  new(sv.getProductVersion, sv.softwareEdition)
end

Instance Method Details

#<=>(other) ⇒ Integer

Comparison against another instance

Parameters:

Returns:

  • (Integer)

    -1 for less, 1 for greater, 0 for equal



40
41
42
43
44
45
# File 'lib/saxon/version/library.rb', line 40

def <=>(other)
  return false unless other.is_a?(self.class)

  n_components = [self.components.length, other.components.length].max
  (0..(n_components - 1)).reduce(0, &comparator(other))
end

#pessimistic_compare(pessimistic_version) ⇒ Boolean

Pessimistic comparison à la rubygems ~>: do I satisfy the other version if considered as a pessimistic version constraint

Parameters:

Returns:

  • (Boolean)

    do I satisfy the constraint?



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/saxon/version/library.rb', line 53

def pessimistic_compare(pessimistic_version)
  pessimistic_components = pessimistic_version.components
  pessimistic_components = pessimistic_components + [0] if pessimistic_components.length == 1
  locked = pessimistic_components[0..-2]
  locked = locked.zip(components[0..locked.length])
  variable = [pessimistic_components[-1], components[locked.length]]

  locked_ok = locked.all? { |check, mine|
    check == mine
  }

  return false unless locked_ok

  check, mine = variable
  mine >= check
end

#to_sString

Returns the version string.

Returns:

  • (String)

    the version string



71
72
73
# File 'lib/saxon/version/library.rb', line 71

def to_s
  version
end