Class: GemCheck::Checker
- Inherits:
-
Object
- Object
- GemCheck::Checker
- Defined in:
- lib/gem-check.rb,
lib/gem-check/cli.rb,
lib/gem-check/helpers.rb
Constant Summary collapse
- URL_GEMCHECK_INFO_JSON =
'https://rubygems.org/api/v1/versions/gem-check.json'
- INFO_FILENAME =
'gem-check.json'
- REPORT_HEADINGS =
['Gem Name', 'Gem Version', 'Version DLs', 'All DLs']
- COL_NAME =
Gem Name
0
- COL_VER =
Version
1
- COL_VDL =
Version DLs
2
- COL_TDL =
Total DLs
3
Class Method Summary collapse
Instance Method Summary collapse
- #build_table ⇒ Object
- #check ⇒ Object
-
#initialize(args = []) ⇒ Checker
constructor
A new instance of Checker.
-
#print_table(table) ⇒ Object
Display.
-
#read_previous_info ⇒ Object
Read stored gem info.
-
#store_new_info ⇒ Object
Save newest gem info to file @f_previous_stats.
Constructor Details
#initialize(args = []) ⇒ Checker
Returns a new instance of Checker.
24 25 26 27 28 29 30 31 32 |
# File 'lib/gem-check.rb', line 24 def initialize(args=[]) @new_downloads = 0 @update_version = nil @current_stats = nil @previous_stats = [] @previous_date = Time.now @f_previous_stats = File.join(Dir.home, INFO_FILENAME) @args = args end |
Class Method Details
.option?(argv, opts) ⇒ Boolean
13 14 15 |
# File 'lib/gem-check/cli.rb', line 13 def self.option?(argv, opts) argv.any? { |option| opts.include?(option) } end |
.show_help ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/gem-check/cli.rb', line 3 def self.show_help puts puts "GemCheck v#{GemCheck::VERSION} - Help" puts "\n Flags:\n" puts " -f Don't save the updated stats for this run." puts " -h Display this help screen." puts " -u Update gem-check." puts end |
.update ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/gem-check/cli.rb', line 17 def self.update puts "\nThis will install the latest version of gem-check." print 'Continue? [Yn] ' response = STDIN.gets.chomp puts "\n" + `gem install gem-check` if response.downcase.include?('y') puts end |
Instance Method Details
#build_table ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gem-check.rb', line 50 def build_table @current_stats = current_gem_info.sort!{|a, b| b[2].to_i <=> a[2].to_i} add_new_download_info(@current_stats) table = Terminal::Table.new(rows: @current_stats) table.title = header_string table.headings = REPORT_HEADINGS [1 ].each{ |col| table.align_column(col, :left) } [2,3].each{ |col| table.align_column(col, :center) } table end |
#check ⇒ Object
34 35 36 37 38 |
# File 'lib/gem-check.rb', line 34 def check read_previous_info print_table(build_table) store_new_info unless @args.include?('-f') end |
#print_table(table) ⇒ Object
Display
62 63 64 |
# File 'lib/gem-check.rb', line 62 def print_table(table) puts "\n#{table}\n\n" end |
#read_previous_info ⇒ Object
Read stored gem info
41 42 43 44 45 46 47 48 |
# File 'lib/gem-check.rb', line 41 def read_previous_info return unless File.exist? @f_previous_stats f = File.read(@f_previous_stats) @previous_date = Time.parse(f.lines.first.chomp) || nil @previous_stats = [] f.lines.drop(1).each { |line| @previous_stats << clean_stat_line(line)} @previous_stats end |
#store_new_info ⇒ Object
Save newest gem info to file @f_previous_stats
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gem-check.rb', line 67 def store_new_info File.open(@f_previous_stats, 'w') do |file| file.write "#{current_date_string}\n" @current_stats.each do |row| row.each_with_index do |col, idx| row[idx] = decommafy(row[idx]).to_i if idx > 1 end file.write row.to_json + "\n" end end end |