Class: GithubScore::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/github_score/cli.rb', line 8

def initialize(argv)
  @argv = argv
  @options = {
    :user => "dhh",
    :PushEvent => "5",
    :PullRequestReviewCommentEvent => "4",
    :WatchEvent => "3",
    :CreateEvent => "2",
    :Other => "1"
  }
  calcuate
  # parse!
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



6
7
8
# File 'lib/github_score/cli.rb', line 6

def arguments
  @arguments
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/github_score/cli.rb', line 6

def options
  @options
end

Instance Method Details

#calcuateObject



45
46
47
48
49
50
51
52
# File 'lib/github_score/cli.rb', line 45

def calcuate
  parse!
  stats = GithubScore::Score.group_issue_types(@options[:user])
  ary = []
  stats.each {|k, v| ary << (v.to_i * multiplier(k).to_i)}
  total = ary.inject(0, :+)
  puts "#{@options[:user]} has the score of #{total}"
end

#parse!Object



41
42
43
# File 'lib/github_score/cli.rb', line 41

def parse!
  parser.parse! @argv
end

#parserObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/github_score/cli.rb', line 22

def parser
  @parser = OptionParser.new do |opts|
    opts.banner = "Usage"

    opts.on("-u", "--user USER", "Github username, default #{@options[:user]}") {|user| @options[:user] = user}

    opts.on("-p", "--PushEvent PushEvent", "Github PushEvent, default #{@options[:PushEvent]}") {|push| @options[:PushEvent] = push}

    opts.on("-P", "--PullRequestReviewCommentEvent PullRequestReviewCommentEvent", 
            "Github PullRequestReviewCommentEvent, default #{@options[:PullRequestReviewCommentEvent]}") {|pull| @options[:PullRequestReviewCommentEvent] = pull}

    opts.on("-w", "--WatchEvent WatchEvent", "Github WatchEvent,  default #{@options[:WatchEvent]}") {|watch| @options[:WatchEvent] = watch}

    opts.on("-c", "--CreateEvent CreateEvent", "Github CreateEvent,  default #{@options[:CreateEvent]}") {|create| @options[:CreateEvent] = create}

    opts.on("-o", "--Other Other Events", "Github Other Events,  default #{@options[:Other]}") {|other| @options[:Other] = other}
  end
end