Module: RubyChopped

Defined in:
lib/ruby_chopped.rb,
lib/ruby_chopped/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.fetch_gemsObject



50
51
52
53
54
# File 'lib/ruby_chopped.rb', line 50

def self.fetch_gems
  gems_json = JSON.parse(RestClient.get("http://rubygems.org/api/v1/downloads/top.json", :accepts => :json))
  gems = gems_json["gems"]    
  gems
end

.gemfile_arrayObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_chopped.rb', line 5

def self.gemfile_array
  gas = []
  gas << "source \"http://rubygems.org\""
  gas << ""
  
  gems = random_gems
  gems.each do |g|
    # Janky way to pull the name
    g = g.first
    name = g["full_name"].split(/-\d\.\d\.\d/).first
    number = g["number"]
    summary = g["summary"]
    
    gas << "# #{name}: #{summary}"
    gas << "gem \"#{name}\", \"#{number}\""
    gas << ""
  end
  
  gas << "# ENJOY!"
  
  gas
end

.gemfile_stringObject



28
29
30
# File 'lib/ruby_chopped.rb', line 28

def self.gemfile_string
  gemfile_array.join("\n")
end

.pick_gems(gems, limit) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_chopped.rb', line 37

def self.pick_gems(gems, limit)
  limit.to_i.times.collect do 
    g = gems.delete_at(rand(gems.size)) 

    # Skip bundler and rails
    if g.first["full_name"][/(bundler|rails)/]
      pick_gems(gems, 1).first
    else
      g
    end
  end
end

.random_gems(limit = 2) ⇒ Object



32
33
34
35
# File 'lib/ruby_chopped.rb', line 32

def self.random_gems(limit=2)
  gems = fetch_gems
  gems = pick_gems(gems, limit)
end