Class: Geoptima::Version
- Inherits:
-
Object
- Object
- Geoptima::Version
- Defined in:
- lib/geoptima/version.rb
Instance Attribute Summary collapse
-
#comparator ⇒ Object
readonly
Returns the value of attribute comparator.
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #as_geoptima_version ⇒ Object
- #clean_version(version) ⇒ Object
- #compare(other) ⇒ Object
- #diff(other) ⇒ Object
-
#initialize(text) ⇒ Version
constructor
A new instance of Version.
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(text) ⇒ Version
Returns a new instance of Version.
7 8 9 10 |
# File 'lib/geoptima/version.rb', line 7 def initialize(text) @comparator,@version = clean_version(text) @major,@minor,@patch=@version.split(/\./) end |
Instance Attribute Details
#comparator ⇒ Object (readonly)
Returns the value of attribute comparator.
6 7 8 |
# File 'lib/geoptima/version.rb', line 6 def comparator @comparator end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
6 7 8 |
# File 'lib/geoptima/version.rb', line 6 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
6 7 8 |
# File 'lib/geoptima/version.rb', line 6 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
6 7 8 |
# File 'lib/geoptima/version.rb', line 6 def patch @patch end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/geoptima/version.rb', line 6 def version @version end |
Instance Method Details
#as_geoptima_version ⇒ Object
33 34 35 |
# File 'lib/geoptima/version.rb', line 33 def as_geoptima_version self end |
#clean_version(version) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/geoptima/version.rb', line 11 def clean_version(version) comparator,cleaned = "==", version if version =~ /^([\>\<\=]+)(\d+\.\d+\.\d+)/ comparator = $1[0..2] cleaned = $2 end [comparator,cleaned] end |
#compare(other) ⇒ Object
36 37 38 39 |
# File 'lib/geoptima/version.rb', line 36 def compare(other) ogv = other.as_geoptima_version self.to_i.send(ogv.comparator, ogv.to_i) end |
#diff(other) ⇒ Object
40 41 42 |
# File 'lib/geoptima/version.rb', line 40 def diff(other) other.as_geoptima_version.to_i - self.to_i end |
#to_i ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/geoptima/version.rb', line 19 def to_i unless @version_int base = 1 @version_int = version.split(/\./).reverse.inject(0) do |acc,v| acc += base * v.to_i base *= 100 acc end end @version_int end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/geoptima/version.rb', line 30 def to_s version end |