Class: Pik::Implementations::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pik/implementations.rb

Direct Known Subclasses

IronRuby, JRuby, Ruby

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



39
40
41
# File 'lib/pik/implementations.rb', line 39

def initialize
  @url = 'http://rubyforge.org'
end

Class Method Details

.find(*args) ⇒ Object



35
36
37
# File 'lib/pik/implementations.rb', line 35

def self.find(*args)
  new.find(*args)
end

Instance Method Details

#find(*args) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/pik/implementations.rb', line 43

def find(*args)
  if args.empty?
    return most_recent
  else
    pattern = Regexp.new(Regexp.escape(args.first))
    versions.select{|v,k| v =~ pattern }.max
  end
end

#most_recent(vers = versions) ⇒ Object



52
53
54
# File 'lib/pik/implementations.rb', line 52

def most_recent(vers=versions)
  vers.max
end

#readObject



62
63
64
65
# File 'lib/pik/implementations.rb', line 62

def read
  uri = URI.parse(@url+@path)
  uri.read
end

#subclassObject



67
68
69
# File 'lib/pik/implementations.rb', line 67

def subclass
  self.class.to_s.split('::').last
end

#versionsObject



56
57
58
59
60
# File 'lib/pik/implementations.rb', line 56

def versions
  vers = read.scan(@re).map{|v| v.reverse}
  vers.map!{ |name, path| [name, @url + path] }.flatten!
  Hash[*vers]
end