Module: Label
- Defined in:
- lib/label.rb,
lib/label/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
-
.describe(gem) ⇒ Object
Describe the given gem.
- .label ⇒ Object
-
.process(gemfile) ⇒ Object
Process the given Gemfile.
-
.read(file) ⇒ Object
Read the given file.
-
.write(file, text) ⇒ Object
Write to the given file.
Class Method Details
.describe(gem) ⇒ Object
Describe the given gem.
gem - A String describing the name of a gem.
Returns a String.
68 69 70 |
# File 'lib/label.rb', line 68 def describe gem Gems.info(gem).fetch "info" end |
.label ⇒ Object
10 11 12 13 14 |
# File 'lib/label.rb', line 10 def label output = process "Gemfile" write "Gemfile", output end |
.process(gemfile) ⇒ Object
Process the given Gemfile.
gemfile - A String describing the path to a Gemfile.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/label.rb', line 19 def process gemfile file = read gemfile lines = file.read.split "\n" processed_lines = [] lines.each_with_index do |line, i| matches = line.match /^( *)gem ['"](.+?)['"]/ if matches previous_line = lines[i - 1] whitespace = matches[1] gem = matches[2] unless previous_line.start_with? "#" processed_lines << "#{whitespace}# #{describe gem}" end end processed_lines << line end processed_lines.join("\n") + "\n" end |
.read(file) ⇒ Object
Read the given file.
file - A String describing the path to a file.
49 50 51 |
# File 'lib/label.rb', line 49 def read file File.open file end |
.write(file, text) ⇒ Object
Write to the given file.
file - A String describing the path to a file. text - A String describing text to be written.
57 58 59 60 61 |
# File 'lib/label.rb', line 57 def write file, text File.open file, "w" do |file| file.write text end end |