Class: Buildhawk

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

Class Method Summary collapse

Class Method Details

.runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/buildhawk.rb', line 6

def self.run
  options = {}
  optparse = OptionParser.new do|opts|
    # Set a banner, displayed at the top
    # of the help screen.
    opts.banner = "Usage: buildhawk [options]"

    # Define the options, and what they do
    options[:title] = nil
    opts.on( '-t', '--title TITLE', 'Set the title of the app' ) do |title|
      options[:title] = title
    end

    # This displays the help screen, all programs are
    # assumed to have this option.
    opts.on( '-h', '--help', 'Display this screen' ) do
      puts opts
      exit
    end
  end

  optparse.parse!

  data = `git log --pretty=format:"%h\t%s\t%N" --show-notes=buildtime | egrep "[0-9]$"`
  data = data.lines.map {|x| 
    x.split("\t") 
  }.map {|x| 
    [to_seconds(x[2].chomp), {:ref => x[0], :subject => x[1..-2] * "\t"}]
  }.reverse

  input = File.read(File.dirname(__FILE__) + '/template.erb')
  eruby = Erubis::Eruby.new(input)

  puts eruby.result(:data => data, :title => options[:title] || "Untitled")
end

.to_seconds(str) ⇒ Object



43
44
45
# File 'lib/buildhawk.rb', line 43

def self.to_seconds(str)
  str.split(':').reverse.to_enum(:map).with_index {|x, i| x.to_f * 60 ** i }.inject {|a, b| a + b }
end