Class: Browserino::Version
- Inherits:
-
Array
- Object
- Array
- Browserino::Version
- Defined in:
- lib/browserino/version.rb
Overview
This class makes versions easily comparable using logical operators it makes it convenient to check versions in a natural way
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.
Instance Method Summary collapse
- #!=(other) ⇒ Object
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #between?(min, max = nil) ⇒ Boolean
- #full ⇒ Object
-
#initialize(val, *rest) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(val, *rest) ⇒ Version
13 14 15 16 17 18 |
# File 'lib/browserino/version.rb', line 13 def initialize(val, *rest) super parse_params(val, *rest) @major = fetch 0, 0 @minor = fetch 1, 0 @patch = fetch 2, 0 end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
11 12 13 |
# File 'lib/browserino/version.rb', line 11 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
11 12 13 |
# File 'lib/browserino/version.rb', line 11 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
11 12 13 |
# File 'lib/browserino/version.rb', line 11 def patch @patch end |
Instance Method Details
#!=(other) ⇒ Object
48 49 50 |
# File 'lib/browserino/version.rb', line 48 def !=(other) compare :!=, other end |
#<(other) ⇒ Object
28 29 30 |
# File 'lib/browserino/version.rb', line 28 def <(other) compare :<, other end |
#<=(other) ⇒ Object
32 33 34 |
# File 'lib/browserino/version.rb', line 32 def <=(other) compare :<=, other end |
#==(other) ⇒ Object
44 45 46 |
# File 'lib/browserino/version.rb', line 44 def ==(other) compare :==, other end |
#>(other) ⇒ Object
36 37 38 |
# File 'lib/browserino/version.rb', line 36 def >(other) compare :>, other end |
#>=(other) ⇒ Object
40 41 42 |
# File 'lib/browserino/version.rb', line 40 def >=(other) compare :>=, other end |
#between?(min, max = nil) ⇒ Boolean
52 53 54 55 56 57 58 59 |
# File 'lib/browserino/version.rb', line 52 def between?(min, max = nil) if min.is_a? Range max = min.max min = min.min end (self >= Version.new(min)) && (self <= Version.new(max)) end |
#full ⇒ Object
20 21 22 |
# File 'lib/browserino/version.rb', line 20 def full to_s end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/browserino/version.rb', line 24 def to_s @to_s ||= join '.' end |