Class: HamlLint::VersionComparer

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/haml_lint/version_comparer.rb

Overview

A simple wrapper around Gem::Version to allow comparison with String instances This makes code shorter in some places

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ VersionComparer

Returns a new instance of VersionComparer.



7
8
9
# File 'lib/haml_lint/version_comparer.rb', line 7

def initialize(version)
  @version = Gem::Version.new(version)
end

Class Method Details

.for_hamlObject



21
22
23
# File 'lib/haml_lint/version_comparer.rb', line 21

def self.for_haml
  new(Haml::VERSION)
end

.for_rubocopObject

Shortcut to create a version comparer for the current RuboCop’s version



17
18
19
# File 'lib/haml_lint/version_comparer.rb', line 17

def self.for_rubocop
  new(RuboCop::Version::STRING)
end

Instance Method Details

#<=>(other) ⇒ Object



12
13
14
# File 'lib/haml_lint/version_comparer.rb', line 12

def <=>(other)
  @version <=> Gem::Version.new(other)
end