Class: Doc::Configurator::Ruby::PathInfo

Inherits:
Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/doc/configurator/ruby/path_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#full_versionObject

Returns the value of attribute full_version

Returns:

  • (Object)

    the current value of full_version



4
5
6
# File 'lib/doc/configurator/ruby/path_info.rb', line 4

def full_version
  @full_version
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/doc/configurator/ruby/path_info.rb', line 4

def name
  @name
end

#partsObject

Returns the value of attribute parts

Returns:

  • (Object)

    the current value of parts



4
5
6
# File 'lib/doc/configurator/ruby/path_info.rb', line 4

def parts
  @parts
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



4
5
6
# File 'lib/doc/configurator/ruby/path_info.rb', line 4

def path
  @path
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



4
5
6
# File 'lib/doc/configurator/ruby/path_info.rb', line 4

def type
  @type
end

Class Method Details

.for_path(path) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/doc/configurator/ruby/path_info.rb', line 10

def self.for_path(path)
  name = path.basename.to_s
  if name =~ /^ruby-(\d+\.\d+\.\d+(?:-p\d+)?)(?i:\.(tar\.(?:gz|bz2)|tgz|tbz|zip))?$/
    extension = $2 ? $2.downcase : :dir
    type = ({'tar.bz2' => 'tbz', 'tar.gz' => 'tgz'}[extension] || extension).to_sym
    new(path, name, type, $1, $1.scan(/\d+/).map(&:to_i))
  end
end

.latest_matching(version, paths) ⇒ Object



6
7
8
# File 'lib/doc/configurator/ruby/path_info.rb', line 6

def self.latest_matching(version, paths)
  paths.map(&method(:for_path)).compact.grep(version).sort.last
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
# File 'lib/doc/configurator/ruby/path_info.rb', line 28

def <=>(other)
  sort_by <=> other.sort_by
end

#===(other) ⇒ Object



32
33
34
# File 'lib/doc/configurator/ruby/path_info.rb', line 32

def ===(other)
  parts === other.parts
end

#sort_byObject



23
24
25
# File 'lib/doc/configurator/ruby/path_info.rb', line 23

def sort_by
  @sort_by ||= [parts, type_priority]
end

#type_priorityObject



19
20
21
# File 'lib/doc/configurator/ruby/path_info.rb', line 19

def type_priority
  @type_priority ||= {:zip => 0, :tgz => 1, :tbz => 2, :dir => 3}[type]
end