Class: Liferaft::Version
- Inherits:
-
Object
- Object
- Liferaft::Version
- Includes:
- Comparable
- 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
-
#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.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/liferaft/version.rb', line 11 def initialize(version_string) components = version_string.downcase.split(/[a-z]/) character = version_string.downcase.gsub(/[^a-z]/, '') if character.length > 2 || character.empty? @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.
9 10 11 |
# File 'lib/liferaft/version.rb', line 9 def build @build end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
9 10 11 |
# File 'lib/liferaft/version.rb', line 9 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
9 10 11 |
# File 'lib/liferaft/version.rb', line 9 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
9 10 11 |
# File 'lib/liferaft/version.rb', line 9 def patch @patch end |
Instance Method Details
#<=>(other) ⇒ Object
30 31 32 33 34 |
# File 'lib/liferaft/version.rb', line 30 def <=>(other) %i(major minor patch build).lazy.map do |component| send(component) <=> other.send(component) end.find(&:nonzero?) || 0 end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/liferaft/version.rb', line 26 def to_s "#{@major}.#{@minor}.#{@patch} Build #{@build}" end |