class Bundleup::VersionSpec
Attributes
operator[R]
parts[R]
Public Class Methods
new(parts:, operator: nil)
click to toggle source
# File lib/bundleup/version_spec.rb, line 15 def initialize(parts:, operator: nil) @parts = parts @operator = operator end
parse(version)
click to toggle source
# File lib/bundleup/version_spec.rb, line 3 def self.parse(version) return version if version.is_a?(VersionSpec) version = version.strip _, operator, number = version.match(/^([^\d\s]*)\s*(.+)/).to_a operator = nil if operator.empty? new(parts: number.split("."), operator: operator) end
Public Instance Methods
==(other)
click to toggle source
# File lib/bundleup/version_spec.rb, line 48 def ==(other) return false unless other.is_a?(VersionSpec) to_s == other.to_s end
exact?()
click to toggle source
# File lib/bundleup/version_spec.rb, line 20 def exact? operator.nil? end
relax()
click to toggle source
# File lib/bundleup/version_spec.rb, line 24 def relax return self if %w[!= > >=].include?(operator) return self.class.parse(">= 0") if %w[< <=].include?(operator) self.class.new(parts: parts, operator: ">=") end
shift(new_version)
click to toggle source
# File lib/bundleup/version_spec.rb, line 31 def shift(new_version) # rubocop:disable Metrics/AbcSize return self.class.parse(new_version) if exact? return self if Gem::Requirement.new(to_s).satisfied_by?(Gem::Version.new(new_version)) return self.class.new(parts: self.class.parse(new_version).parts, operator: "<=") if %w[< <=].include?(operator) new_slice = self.class.parse(new_version).slice(parts.length) self.class.new(parts: new_slice.parts, operator: "~>") end
slice(amount)
click to toggle source
# File lib/bundleup/version_spec.rb, line 40 def slice(amount) self.class.new(parts: parts[0, amount], operator: operator) end
to_s()
click to toggle source
# File lib/bundleup/version_spec.rb, line 44 def to_s [operator, parts.join(".")].compact.join(" ") end