Class: SemanticRange::Comparator
- Inherits:
-
Object
- Object
- SemanticRange::Comparator
- Defined in:
- lib/semantic_range/comparator.rb
Instance Attribute Summary collapse
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#semver ⇒ Object
readonly
Returns the value of attribute semver.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(comp, loose) ⇒ Comparator
constructor
A new instance of Comparator.
- #parse(comp) ⇒ Object
- #test(version) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(comp, loose) ⇒ Comparator
Returns a new instance of Comparator.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/semantic_range/comparator.rb', line 4 def initialize(comp, loose) if comp.is_a?(Comparator) return comp if comp.loose == loose @comp = comp.value end @loose = loose parse(comp) @value = @semver == ANY ? '' : @operator + @semver.version end |
Instance Attribute Details
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
3 4 5 |
# File 'lib/semantic_range/comparator.rb', line 3 def operator @operator end |
#semver ⇒ Object (readonly)
Returns the value of attribute semver.
3 4 5 |
# File 'lib/semantic_range/comparator.rb', line 3 def semver @semver end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/semantic_range/comparator.rb', line 3 def value @value end |
Instance Method Details
#parse(comp) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/semantic_range/comparator.rb', line 26 def parse(comp) m = comp.match(@loose ? COMPARATORLOOSE : COMPARATOR) raise InvalidComparator.new(comp) unless m @operator = m[1] @operator = '' if @operator == '=' @semver = !m[2] ? ANY : Version.new(m[2], @loose) end |
#test(version) ⇒ Object
20 21 22 23 24 |
# File 'lib/semantic_range/comparator.rb', line 20 def test(version) return true if @semver == ANY version = Version.new(version, @loose) if version.is_a?(String) SemanticRange.cmp(version, @operator, @semver, @loose) end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/semantic_range/comparator.rb', line 16 def to_s @value end |