Class: SortedSearch::GitHubPrinter

Inherits:
Printer
  • Object
show all
Defined in:
lib/sorted_search/printers/github_printer.rb

Overview

Printer for pods specification

Instance Method Summary collapse

Instance Method Details

#distance_from_now_in_words(from_time) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sorted_search/printers/github_printer.rb', line 42

def distance_from_now_in_words(from_time)
  return nil unless from_time
  from_time = Time.parse(from_time) unless from_time.is_a?(Time)
  to_time = Time.now
  distance_in_days = (((to_time - from_time).abs) / 60 / 60 / 24).round

  case distance_in_days
    when 0..7
      "less than a week ago"
    when 8..29
      "#{distance_in_days} days ago"
    when 30..45
      "1 month ago"
    when 46..365
      "#{(distance_in_days.to_f / 30).round} months ago"
    else
      "more than a year ago"
  end
end


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/sorted_search/printers/github_printer.rb', line 10

def print(pods)

  pods.each do |array|
    pod = array[0]
    mash = array[1]

    Pod::UI.title("-> #{pod.name} (#{pod.version})".green, '', 1) do
      stars = [0x2605].pack('U') + '  '
      forks = [0x2442].pack('U') + ' '
      commit = 'Last commit: '

      if mash.name
        stars  += mash.stargazers_count.to_s + ' '
        forks  += mash.forks.to_s + ' '
        commit += distance_from_now_in_words(mash.pushed_at)
      else
        stars  += "Unknown "
        forks  += "Unknown "
        commit += "Unknown "
      end

      Pod::UI.puts_indented pod.summary
      Pod::UI.puts_indented "pod '#{pod.name}', '~> #{pod.version}'"
      Pod::UI.puts_indented pod.homepage
      Pod::UI.puts_indented stars.yellow + forks.yellow
      Pod::UI.puts_indented commit.yellow
    end
  end

  Pod::UI.puts
end