myprecious 0.0.3 → 0.0.4

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/myprecious.rb +94 -30
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ced07b0dd9cf34ff71b1284ee5f6869b1136524b
4
- data.tar.gz: 00ab489774c7dbbdeab4f062c6525f489231e5e1
3
+ metadata.gz: b943f489c99bee0c0196fc99dabbe344113b2e5f
4
+ data.tar.gz: 1ee1410f7c4d607f9c43444aa4803b2e0f20f72e
5
5
  SHA512:
6
- metadata.gz: 71a804e5f5aed017859b9b12a428d45429e5df07fe5c2cf7e65dd23b28e6c9040ff15fbad769090c4b03c66d88dd2c07104627a564b166250d0c84e09ba2a845
7
- data.tar.gz: 5558b007a05a0f64f40f0f1a2d0e63a797c24594aee546e0d3939d60e37bf76eb5b0ef5541cc916a93d8a6987d57a3c72f640c72f169fdf394a565eb917a74d6
6
+ metadata.gz: 1aad09474b21bb26fc7ba3ae72ff3c47ea59ac5958a3f7e28af8568eea1d72e1ff93f21ba058dfdceb2077d8f7d9bd59b53dd3374ca2f0ecc374b14ee0422eb6
7
+ data.tar.gz: 547fe32c28a3ba30c8c7dcc4d11b1ae07320eef7c43c18ddbcf95bb091e08560b57ad4846d2fe0672a96e94ec73b0b915b23e6b4a9893c4f9ffb89823d3a4cc2
@@ -3,45 +3,109 @@ require 'date'
3
3
 
4
4
  class MyPrecious
5
5
  def self.update
6
+ gem_lines = {}
7
+ gem_name_pos = 0
8
+ gem_version_pos = 1
9
+ gem_latest_pos = 2
10
+ gem_date_pos = 3
11
+ gem_age_pos = 4
12
+ gem_license_pos = 5
13
+ gem_change_pos = 6
14
+ default_length = 7
15
+ if File.file?('myprecious.md')
16
+ File.open("myprecious.md", "r").each_with_index do |line, line_number|
17
+ #puts line + " dds " + line_number.to_s
18
+ word_array = line.split('|')
19
+ if line_number == 0
20
+ default_length = word_array.size
21
+ word_array.each_with_index do |word, index|
22
+ if word.strip == 'Gem'
23
+ gem_name_pos = index
24
+ elsif word.strip == 'Our Version'
25
+ gem_version_pos = index
26
+ elsif word.strip == 'Latest Version'
27
+ gem_latest_pos = index
28
+ elsif word.strip == 'Date available'
29
+ gem_date_pos = index
30
+ elsif word.strip == 'Age (in days)'
31
+ gem_age_pos = index
32
+ elsif word.strip == 'License Type'
33
+ gem_change_pos = index
34
+ elsif word.strip == 'Change Log'
35
+ gem_change_pos = index
36
+ end
37
+ end
38
+ elsif line_number > 1
39
+ gem_name_index = word_array[gem_name_pos].strip
40
+ #extract just the name of the gem from the first column
41
+ #since that column contains a markdown-formatted hyperlink
42
+ gem_name_index = gem_name_index[/\[(.*?)\]/,1]
43
+ gem_lines[gem_name_index] = line_number
44
+ end
45
+
46
+ end
47
+ #puts gem_lines
48
+ else
49
+ File.open('myprecious.md', 'w') { |write_file|
50
+ write_file.puts "Gem | Our Version | Latest Version | Date available | Age (in days) | License Type | Change Log"
51
+ write_file.puts "--- | --- | --- | --- | --- | --- | ---"
52
+ }
53
+ end
54
+
6
55
  file = File.new("Gemfile", "r")
7
56
 
8
- File.open('myprecious.md', 'w') { |write_file|
9
- write_file.puts "gem | Our Version | Latest Version | Date available | Age (in days) | Change Log"
10
- write_file.puts "--- | --- | --- | --- | --- | ---"
11
- while (line = file.gets)
12
- gem_line = line.strip
13
- if (gem_line.include? 'gem') && !gem_line.start_with?('#') && !gem_line.start_with?('source')
14
- name = gem_line.split(' ')[1].split(',')[0].split('\'')[1]
15
- # gems_info = Gems.versions name
16
- begin
17
- a = require name
18
- if a
19
- current_version = Gem::Specification.find_all_by_name(name).max.version
20
- gems_info = Gems.versions name
21
- gems_latest_info = Gems.info name
22
- latest_build = ''
57
+ final_write = File.readlines('myprecious.md')
23
58
 
24
- gems_info.each do |gem_info|
25
- if gem_info["number"].to_s == gems_latest_info["version"].to_s
26
- latest_build = Date.parse gem_info["built_at"]
59
+ while (line = file.gets)
60
+ gem_line = line.strip
61
+ if (gem_line.include? 'gem') && !gem_line.start_with?('#') && !gem_line.start_with?('source')
62
+ begin
63
+ name = gem_line.split(' ')[1].split(',')[0].tr(" '\"", "")
64
+ a = require name
65
+ if a
66
+ current_version = Gem::Specification.find_all_by_name(name).max.version
67
+
68
+ gems_info = Gems.versions name
69
+ gems_latest_info = Gems.info name
70
+ latest_build = ''
71
+ gems_info.each do |gem_info|
72
+ if gem_info["number"].to_s == gems_latest_info["version"].to_s
73
+ latest_build = Date.parse gem_info["built_at"]
74
+ end
75
+ if gem_info["number"].to_s == current_version.to_s
76
+ current_build = Date.parse gem_info["built_at"]
77
+
78
+ days_complete = latest_build - current_build
79
+ if gem_lines[name].nil?
80
+ array_to_write = Array.new(default_length) { |i| "" }
81
+ else
82
+ array_to_write = final_write[gem_lines[name]].split('|')
27
83
  end
28
- if gem_info["number"].to_s == current_version.to_s
29
- current_build = Date.parse gem_info["built_at"]
30
- days_complete = latest_build - current_build
31
- write_file.puts "[" + name + "]" + "(" + gems_latest_info["homepage_uri"].to_s + ")" +
32
- "|" + current_version.to_s + "|" + gems_latest_info["version"].to_s + "|" +
33
- (latest_build).to_s + "|" + days_complete.to_i.to_s +
34
- "|" + gems_latest_info["changelog_uri"].to_s
84
+ array_to_write[gem_name_pos] = "[" + name + "]" + "(" + gems_latest_info["homepage_uri"].to_s + ")"
85
+ array_to_write[gem_version_pos] = current_version.to_s
86
+ array_to_write[gem_latest_pos] = gems_latest_info["version"].to_s
87
+ array_to_write[gem_date_pos] = (latest_build).to_s
88
+ array_to_write[gem_age_pos] = days_complete.to_i.to_s
89
+ if !gem_info["licenses"].nil?
90
+ array_to_write[gem_license_pos] = gem_info["licenses"][0]
91
+ else
92
+ array_to_write[gem_license_pos] = "N/A"
93
+ end
94
+ array_to_write[gem_change_pos] = gems_latest_info["changelog_uri"].to_s + "\n"
95
+ if !gem_lines[name].nil?
96
+ final_write[gem_lines[name]] = array_to_write.join("|")
97
+ else
98
+ final_write << array_to_write.join("|")
35
99
  end
36
100
  end
37
-
38
101
  end
39
- rescue Exception => e
40
-
41
102
  end
103
+ rescue Exception => e
104
+ puts e
42
105
  end
43
106
  end
44
- file.close
45
- }
107
+ end
108
+ File.open('myprecious.md', 'w') { |f| f.write(final_write.join) }
109
+ file.close
46
110
  end
47
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myprecious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balki Kodarapu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-24 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple, markdown generated with information about your gems
14
14
  email: balki.kodarapu@gmail.com