my_gems_summary 1.9 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/my_gems.rb +33 -16
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e4d06cab4aca96fbb1aed48190fa1d263ceeb9579e76606d29977008f9495d7
4
- data.tar.gz: f57e77ad2cbb254720498728d771b8167ca33b8163935fe9cc53453382d0437c
3
+ metadata.gz: da9d1a6ba99119d2d1676383249150b0426eeec6e58ac96b8e8b4c0935929434
4
+ data.tar.gz: ffa25cc33a588b889b645af17ba07eca69855e57ace48492e61bcf0d0a5ec8eb
5
5
  SHA512:
6
- metadata.gz: cb4633be8cfa8ea985fad678c0cb272fc4eafea1bc753e75a42b81dde4e2a689e8dd6b8033079c8b8565cf11b84741a9a2f48be667948f86f6da2364d4d8976c
7
- data.tar.gz: cd85c610ac05d9a77f26a2e7340ef9d76d77681a05774dcae470e0c3e89320d65ca8f01ab2d9ca44bc87c3595ba522a9274b1f870457c8bd96a580d595a0171f
6
+ metadata.gz: 3e7dfc6280ed49334a1be4cfc18c8ef0e7226e3acb1fb932233543676d86007d2b8b2bb83cca93bf36bbdec63fe4133cc806eeb098e8a0c7a08f72131f81fd9b
7
+ data.tar.gz: 2f29383a74fb0db90a8cc0d157a9e07384619ea5ac755207ebf4018698366aeaefe9be88e90fc28d2d6048a42859033b95e8c65b79c2f96eaa9cebf88348ace6
data/lib/my_gems.rb CHANGED
@@ -1,37 +1,54 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'gems'
2
4
 
3
5
  GemDTO = Struct.new(:name, :downloads)
4
6
 
5
7
  module MyGems
6
8
  def self.valid_credentials?
7
- begin
8
- Gems.gems
9
- rescue
10
- puts '🥺 Opps, looks like we are missing your rubygems.org credentials 😭'
11
- puts "🥺 Let's authenticate 😭"
9
+ Gems.gems
10
+ rescue StandardError
11
+ puts '🥺 Opps, looks like we are missing your rubygems.org credentials 😭'
12
+ puts "🥺 Let's authenticate 😭"
12
13
 
13
- puts "💻 Please run 'gem signin' and try again 💻"
14
- end
14
+ puts "💻 Please run 'gem signin' and try again 💻"
15
+ end
16
+
17
+ def self.my_gems
18
+ gems = Gems.gems.map { |gem| GemDTO.new(gem['name'], gem['downloads']) }
19
+ gems.sort_by(&:downloads).reverse
20
+ end
21
+
22
+ def self.valid_gems?(gems)
23
+ return gems unless gems.empty?
24
+
25
+ puts '🥺 Opps, looks like you have no gems 😭'
26
+ puts "🥺 Let's add some 💻"
27
+
28
+ puts "💻 Please run 'gem build & gem push' and try again 💻"
29
+ puts "💻 Maybe you can find some funny stuff here github.com/kammradt 💻"
30
+ end
31
+
32
+ def self.gem_with_longest_name(gems)
33
+ gems.max_by { |gem| gem.name.length }
15
34
  end
16
35
 
17
36
  def self.show
18
37
  puts "⭐ Let's see if you're a star!⭐ "
19
38
  return unless valid_credentials?
20
39
 
40
+ gems = my_gems
41
+ return unless valid_gems?(gems)
42
+
21
43
  puts "📚 Here's your summary:"
22
44
  puts "\n"
23
-
24
- my_gems = Gems.gems.map { |gem| GemDTO.new(gem['name'], gem['downloads']) }
25
- my_gems = my_gems.sort_by(&:downloads).reverse
26
-
27
- gem_with_longest_name = my_gems.max_by { |gem| gem.name.length }
28
-
29
- my_gems.each do |gem|
30
- name_output = gem.name.ljust(gem_with_longest_name.first.length)
45
+
46
+ gems.each do |gem|
47
+ name_output = gem.name.ljust(gem_with_longest_name(gems).name.length)
31
48
  puts "🛑 #{name_output} 🔝 #{gem.downloads} downloads"
32
49
  end
33
50
 
34
51
  puts "\n"
35
- puts "Bye! See you soon 👋👋👋"
52
+ puts 'Bye! See you soon 👋👋👋'
36
53
  end
37
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_gems_summary
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.9'
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinicius Kammradt