Class: Saxon::Version::Library
- Inherits:
-
Object
- Object
- Saxon::Version::Library
- 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
-
#components ⇒ String
readonly
The version components (e.g.
[9, 9, 1, 6]
,[10, 0]
). -
#edition ⇒ Symbol
readonly
The edition (
:he
,:pe
, or:ee
). -
#version ⇒ String
readonly
The version string (e.g. ‘9.9.1.6’, ‘10.0’).
Class Method Summary collapse
-
.loaded_version ⇒ Saxon::Version::Library
The loaded version of the Saxon Java library.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Comparison against another instance.
-
#initialize(version, edition) ⇒ Library
constructor
A new instance of Library.
-
#pessimistic_compare(pessimistic_version) ⇒ Boolean
Pessimistic comparison à la rubygems ~>: do I satisfy the other version if considered as a pessimistic version constraint.
-
#to_s ⇒ String
The version string.
Constructor Details
#initialize(version, edition) ⇒ Library
Returns a new instance of Library.
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
#components ⇒ String (readonly)
Returns 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 |
#edition ⇒ Symbol (readonly)
Returns the edition (:he
, :pe
, or :ee
).
25 26 27 |
# File 'lib/saxon/version/library.rb', line 25 def edition @edition end |
#version ⇒ String (readonly)
Returns 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_version ⇒ Saxon::Version::Library
The loaded version of the Saxon Java library
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
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
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_s ⇒ String
Returns the version string.
71 72 73 |
# File 'lib/saxon/version/library.rb', line 71 def to_s version end |