class Semvruler::Rule
Attributes
constraints[R]
Public Class Methods
new(constraints)
click to toggle source
# File lib/semvruler/rule.rb, line 12 def initialize(constraints) @constraints = Hash[constraints.map { |c| [c.to_s, c] }] end
parse(value)
click to toggle source
# File lib/semvruler/rule.rb, line 6 def parse(value) constraints = Array(Constraint.parse(value, safe: false)) new(constraints) end
Public Instance Methods
[](idx)
click to toggle source
# File lib/semvruler/rule.rb, line 16 def [](idx) constraints[idx] end
add(value)
click to toggle source
# File lib/semvruler/rule.rb, line 24 def add(value) constraint = Constraint.parse(value) constraints[constraint.to_s] = constraint end
match?(version)
click to toggle source
# File lib/semvruler/rule.rb, line 39 def match?(version) constraints.values.all? { |c| c.match?(version) } end
merge(other)
click to toggle source
# File lib/semvruler/rule.rb, line 34 def merge(other) new_constraints = [*constraints.values, *other.constraints.values] self.class.new(new_constraints) end
remove(value)
click to toggle source
# File lib/semvruler/rule.rb, line 29 def remove(value) constraint = Constraint.parse(value) constraints.delete(constraint.to_s) end
size()
click to toggle source
# File lib/semvruler/rule.rb, line 20 def size constraints.size end
to_proc()
click to toggle source
# File lib/semvruler/rule.rb, line 43 def to_proc ->(version) { match?(version) } end