Class: Semvruler::Constraint
- Inherits:
-
Object
- Object
- Semvruler::Constraint
- Defined in:
- lib/semvruler/constraint.rb
Defined Under Namespace
Classes: FormatError
Constant Summary collapse
- FORMAT =
/^((?<type>=|!=|~>|>=|>|<=|<)\s*)?(?<version>.*)$/.freeze
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, version) ⇒ Constraint
constructor
A new instance of Constraint.
- #match?(other) ⇒ Boolean
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(type, version) ⇒ Constraint
Returns a new instance of Constraint.
47 48 49 50 |
# File 'lib/semvruler/constraint.rb', line 47 def initialize(type, version) @type = type @version = version end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
41 42 43 |
# File 'lib/semvruler/constraint.rb', line 41 def version @version end |
Class Method Details
.parse(value, safe: true) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/semvruler/constraint.rb', line 14 def parse(value, safe: true) if value.respond_to?(:map) value.map { |item| cast(item, safe) } else cast(value, safe) end end |
Instance Method Details
#match?(other) ⇒ Boolean
56 57 58 59 |
# File 'lib/semvruler/constraint.rb', line 56 def match?(other) other = Semversion.parse(other, safe: false) other.send(operation, version) end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/semvruler/constraint.rb', line 43 def to_s "#{type_as_string}#{version}" end |
#type ⇒ Object
52 53 54 |
# File 'lib/semvruler/constraint.rb', line 52 def type @type || '=' end |