Class: Calabash::Cucumber::Version
- Inherits:
-
Object
- Object
- Calabash::Cucumber::Version
- Defined in:
- lib/calabash-cucumber/version.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#patch ⇒ Object
Returns the value of attribute patch.
-
#pre ⇒ Object
Returns the value of attribute pre.
-
#pre_version ⇒ Object
Returns the value of attribute pre_version.
Instance Method Summary collapse
- #!=(other) ⇒ Object
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #compare(a, b) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Returns a new instance of Version.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/calabash-cucumber/version.rb', line 23 def initialize(version) tokens = version.split('.') count = tokens.count if count == 4 @pre = tokens[3] pre_tokens = @pre.scan(/\D+|\d+/) @pre_version = pre_tokens[1].to_i if pre_tokens.count == 2 end @major, @minor, @patch = version.split('.').map(&:to_i) end |
Instance Attribute Details
#major ⇒ Object
Returns the value of attribute major.
17 18 19 |
# File 'lib/calabash-cucumber/version.rb', line 17 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
18 19 20 |
# File 'lib/calabash-cucumber/version.rb', line 18 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
19 20 21 |
# File 'lib/calabash-cucumber/version.rb', line 19 def patch @patch end |
#pre ⇒ Object
Returns the value of attribute pre.
20 21 22 |
# File 'lib/calabash-cucumber/version.rb', line 20 def pre @pre end |
#pre_version ⇒ Object
Returns the value of attribute pre_version.
21 22 23 |
# File 'lib/calabash-cucumber/version.rb', line 21 def pre_version @pre_version end |
Instance Method Details
#!=(other) ⇒ Object
45 46 47 |
# File 'lib/calabash-cucumber/version.rb', line 45 def != (other) compare(self, other) != 0 end |
#<(other) ⇒ Object
49 50 51 |
# File 'lib/calabash-cucumber/version.rb', line 49 def < (other) compare(self, other) < 0 end |
#<=(other) ⇒ Object
57 58 59 |
# File 'lib/calabash-cucumber/version.rb', line 57 def <= (other) compare(self, other) <= 0 end |
#==(other) ⇒ Object
41 42 43 |
# File 'lib/calabash-cucumber/version.rb', line 41 def == (other) compare(self, other) == 0 end |
#>(other) ⇒ Object
53 54 55 |
# File 'lib/calabash-cucumber/version.rb', line 53 def > (other) compare(self, other) > 0 end |
#>=(other) ⇒ Object
61 62 63 |
# File 'lib/calabash-cucumber/version.rb', line 61 def >= (other) compare(self, other) >= 0 end |
#compare(a, b) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/calabash-cucumber/version.rb', line 65 def compare(a, b) if a.major != b.major return a.major > b.major ? 1 : -1 end if a.minor != b.minor return a.minor > b.minor ? 1 : -1 end if a.patch != b.patch return a.patch > b.patch ? 1 : -1 end return 1 if a.pre and (not b.pre) return -1 if (not a.pre) and b.pre return 1 if a.pre_version and (not b.pre_version) return -1 if (not a.pre_version) and b.pre_version if a.pre_version != b.pre_version return a.pre_version > b.pre_version ? 1 : -1 end 0 end |
#to_s ⇒ Object
35 36 37 38 39 |
# File 'lib/calabash-cucumber/version.rb', line 35 def to_s str = [@major, @minor, @patch].join('.') str = "#{str}.#{@pre}" if @pre str end |