Class: Version
- Inherits:
-
Object
- Object
- Version
- Defined in:
- lib/atk/version.rb
Overview
create a variable for the current ruby version
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.
Instance Method Summary collapse
- #<(other_version) ⇒ Object
- #<=>(other_version) ⇒ Object
- #==(other_version) ⇒ Object
- #>(other_version) ⇒ Object
-
#initialize(version_as_string) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(version_as_string) ⇒ Version
Returns a new instance of Version.
6 7 8 9 10 |
# File 'lib/atk/version.rb', line 6 def initialize(version_as_string) # TODO: make this more safe/better error handling @major, @minor, @patch = version_as_string.split('.').map{|each| each.to_i} @as_string = version_as_string end |
Instance Attribute Details
#major ⇒ Object
Returns the value of attribute major.
4 5 6 |
# File 'lib/atk/version.rb', line 4 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
4 5 6 |
# File 'lib/atk/version.rb', line 4 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
4 5 6 |
# File 'lib/atk/version.rb', line 4 def patch @patch end |
Instance Method Details
#<(other_version) ⇒ Object
26 27 28 |
# File 'lib/atk/version.rb', line 26 def <(other_version) return (self <=> other_version) == -1 end |
#<=>(other_version) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/atk/version.rb', line 12 def <=>(other_version) if not other_version.is_a?(Version) raise "When doing version comparision, both sides must be a version object" end major_size = (@major <=> other_version.major * 100) minor_size = (@minor <=> other_version.minor * 10 ) patch_size = (@patch <=> other_version.patch * 1 ) return (major_size + minor_size + patch_size) <=> 0 end |
#==(other_version) ⇒ Object
30 31 32 |
# File 'lib/atk/version.rb', line 30 def ==(other_version) return (self <=> other_version) == 0 end |
#>(other_version) ⇒ Object
22 23 24 |
# File 'lib/atk/version.rb', line 22 def >(other_version) return (self <=> other_version) == 1 end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/atk/version.rb', line 34 def to_s return "#{@major}.#{@minor}.#{@patch}" end |