Class: GitPissed::WordFinder

Inherits:
Struct
  • Object
show all
Defined in:
lib/git_pissed/word_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



2
3
4
# File 'lib/git_pissed/word_finder.rb', line 2

def options
  @options
end

#revisionsObject

Returns the value of attribute revisions

Returns:

  • (Object)

    the current value of revisions



2
3
4
# File 'lib/git_pissed/word_finder.rb', line 2

def revisions
  @revisions
end

Instance Method Details

#by_dateObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/git_pissed/word_finder.rb', line 3

def by_date
  with_sorted_dates do |dates|
    revisions.each do |revision|
      date = git.date_for(revision)

      options.words.each do |word|
        dates[date][word] = [
          dates[date][word], git.count_for(word, revision)
        ].max

        progress_bar.increment
      end
    end
  end
end

#gitObject



33
34
35
# File 'lib/git_pissed/word_finder.rb', line 33

def git
  Git.new(options)
end

#progress_barObject



25
26
27
28
29
30
31
# File 'lib/git_pissed/word_finder.rb', line 25

def progress_bar
  @progress_bar ||= begin
    ProgressBar.create \
      :total  => (revisions.count * options.words.count),
      :format => '%e <%B> %p%% %t'
  end
end

#with_sorted_dates {|dates| ... } ⇒ Object

Yields:

  • (dates)


19
20
21
22
23
# File 'lib/git_pissed/word_finder.rb', line 19

def with_sorted_dates
  dates = Hash.new { |hash, key| hash[key] = Hash.new(0) }
  yield dates
  dates.sort { |(k1, v1), (k2, v2)| k1 <=> k2 }
end