Class: LockOMotion::GemPath

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/lock-o-motion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ GemPath

Returns a new instance of GemPath.



17
18
19
20
21
# File 'lib/lock-o-motion.rb', line 17

def initialize(path)
  @name, @version = File.basename(path).scan(/^(.+?)-([^-]+)$/).flatten
  @path = path
  @version_numbers = @version.split(/[^0-9]+/).collect(&:to_i)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/lock-o-motion.rb', line 14

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/lock-o-motion.rb', line 14

def path
  @path
end

#versionObject (readonly)

Returns the value of attribute version.



14
15
16
# File 'lib/lock-o-motion.rb', line 14

def version
  @version
end

#version_numbersObject (readonly)

Returns the value of attribute version_numbers.



14
15
16
# File 'lib/lock-o-motion.rb', line 14

def version_numbers
  @version_numbers
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
26
# File 'lib/lock-o-motion.rb', line 23

def <=>(other)
  raise "Not comparable gem paths ('#{name}' is not '#{other.name}')" unless name == other.name
  @version_numbers <=> other.version_numbers
end