Class: Solve::Version
- Inherits:
-
Object
- Object
- Solve::Version
- Includes:
- Comparable
- Defined in:
- lib/solve/version.rb
Overview
Instance Attribute Summary collapse
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Integer
- #eql?(other) ⇒ Boolean
-
#initialize(*args) ⇒ Version
constructor
A new instance of Version.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version_array) ⇒ Version #initialize(version_string) ⇒ Version #initialize(version) ⇒ Version
Returns a new instance of Version.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/solve/version.rb', line 46 def initialize(*args) if args.first.is_a?(Array) @major, @minor, @patch = args.first else @major, @minor, @patch = self.class.split(args.first.to_s) end @major ||= 0 @minor ||= 0 @patch ||= 0 end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
24 25 26 |
# File 'lib/solve/version.rb', line 24 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
25 26 27 |
# File 'lib/solve/version.rb', line 25 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
26 27 28 |
# File 'lib/solve/version.rb', line 26 def patch @patch end |
Class Method Details
.split(version_string) ⇒ Array
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/solve/version.rb', line 10 def split(version_string) major, minor, patch = case version_string.to_s when /^(\d+)\.(\d+)\.(\d+)$/ [ $1.to_i, $2.to_i, $3.to_i ] when /^(\d+)\.(\d+)$/ [ $1.to_i, $2.to_i, nil ] else raise Errors::InvalidVersionFormat.new(version_string) end end |
Instance Method Details
#<=>(other) ⇒ Integer
61 62 63 64 65 66 67 |
# File 'lib/solve/version.rb', line 61 def <=>(other) [:major, :minor, :patch].each do |method| ans = (self.send(method) <=> other.send(method)) return ans if ans != 0 end 0 end |
#eql?(other) ⇒ Boolean
72 73 74 |
# File 'lib/solve/version.rb', line 72 def eql?(other) other.is_a?(Version) && self == other end |
#inspect ⇒ Object
76 77 78 |
# File 'lib/solve/version.rb', line 76 def inspect to_s end |
#to_s ⇒ Object
80 81 82 |
# File 'lib/solve/version.rb', line 80 def to_s "#{major}.#{minor}.#{patch}" end |