Class: Liferaft::Version
- Inherits:
-
Object
- Object
- Liferaft::Version
- Defined in:
- lib/liferaft/version.rb
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#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.
Instance Method Summary collapse
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
-
#initialize(version_string) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(version_string) ⇒ Version
Returns a new instance of Version.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/liferaft/version.rb', line 9 def initialize(version_string) components = version_string.downcase.split(/[a-z]/) character = version_string.downcase.gsub(/[^a-z]/, '') if character.length > 2 || character.length == 0 @major = @minor = @patch = @build = 0 return end @major = components[0].to_i @minor = character.ord - 'a'.ord @patch = components[1].to_i / 1000 @build = (character.length == 2 ? character[-1].ord : 0) + components[1].to_i % 1000 end |
Instance Attribute Details
#build ⇒ Object (readonly)
Returns the value of attribute build.
7 8 9 |
# File 'lib/liferaft/version.rb', line 7 def build @build end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
7 8 9 |
# File 'lib/liferaft/version.rb', line 7 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
7 8 9 |
# File 'lib/liferaft/version.rb', line 7 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
7 8 9 |
# File 'lib/liferaft/version.rb', line 7 def patch @patch end |
Instance Method Details
#<(other) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/liferaft/version.rb', line 36 def <(other) return true if major < other.major return false if major != other.major return true if minor < other.minor return false if minor != other.minor return true if patch < other.patch return false if patch != other.patch build < other.build end |
#<=(other) ⇒ Object
46 47 48 |
# File 'lib/liferaft/version.rb', line 46 def <=(other) self < other || other == self end |
#==(other) ⇒ Object
50 51 52 53 54 |
# File 'lib/liferaft/version.rb', line 50 def ==(other) other.instance_of?(self.class) && major == other.major && minor == other.minor && patch == other.patch && build == other.build end |
#>(other) ⇒ Object
28 29 30 |
# File 'lib/liferaft/version.rb', line 28 def >(other) other < self end |
#>=(other) ⇒ Object
32 33 34 |
# File 'lib/liferaft/version.rb', line 32 def >=(other) other < self || other == self end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/liferaft/version.rb', line 24 def to_s return "#{@major}.#{@minor}.#{@patch} Build #{@build}" end |