class Browserino::Version
This class makes versions easily comparable using logical operators it makes it convenient to check versions in a natural way
Attributes
major[R]
minor[R]
patch[R]
Public Class Methods
new(val, *rest)
click to toggle source
Calls superclass method
# 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
Public Instance Methods
!=(other)
click to toggle source
# File lib/browserino/version.rb, line 48 def !=(other) compare :!=, other end
<(other)
click to toggle source
# File lib/browserino/version.rb, line 28 def <(other) compare :<, other end
<=(other)
click to toggle source
# File lib/browserino/version.rb, line 32 def <=(other) compare :<=, other end
==(other)
click to toggle source
# File lib/browserino/version.rb, line 44 def ==(other) compare :==, other end
>(other)
click to toggle source
# File lib/browserino/version.rb, line 36 def >(other) compare :>, other end
>=(other)
click to toggle source
# File lib/browserino/version.rb, line 40 def >=(other) compare :>=, other end
between?(min, max = nil)
click to toggle source
# 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()
click to toggle source
# File lib/browserino/version.rb, line 20 def full to_s end
to_s()
click to toggle source
# File lib/browserino/version.rb, line 24 def to_s @to_s ||= join '.' end
Private Instance Methods
compare(opr, other)
click to toggle source
# File lib/browserino/version.rb, line 75 def compare(opr, other) other = Version.new other unless other.is_a? Version subsize = [size, other.size].min return if subsize.zero? && size > 0 (self[0...subsize] <=> other[0...subsize]).send opr, 0 end
parse_params(val, *rest)
click to toggle source
# File lib/browserino/version.rb, line 63 def parse_params(val, *rest) case val when Integer then [val, *rest] when String then val.tr('_', '.').split '.' when Array then val when Hash then [val[:major], val[:minor], val[:patch]] when Symbol then [] when Float then val.to_s.split('.').map(&:to_i) else val.to_a end.map(&:to_i) end