getcomments 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +29 -9
- data/lib/getcomments.rb +11 -1
- data/lib/getcomments/{read.rb → code.rb} +14 -14
- data/lib/getcomments/version.rb +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c302859eeba8bb1f91ee222ced925aa24a5e9fef97f2485db3c5f7a14defe4c
|
4
|
+
data.tar.gz: bf5f7894e2bb22879ad1e7c4fa045b7b21369be02ea18a99e992c46bb5b3ae9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cc69c370c1b6843ac2b6bd127135682689609b11a43b7fb66e5d1c1209aaf3205983404faee234e9d132e551c1f0e92761e1a5f665af98e0a14a8de2225b4e2
|
7
|
+
data.tar.gz: 1a1f50ad2b81fb98422ab239457c61b877be8ad780389667d2d945055dfee8978569bc5508b3fc55e74f62d7724767ad4258b97851a7703f5ff9d0f86325c054
|
data/README.md
CHANGED
@@ -4,7 +4,6 @@ GetComments - Extract Comments from Ruby Code
|
|
4
4
|
[](https://badge.fury.io/rb/getcomments)
|
5
5
|
[](https://travis-ci.com/DannyBen/getcomments)
|
6
6
|
[](https://codeclimate.com/github/DannyBen/getcomments/maintainability)
|
7
|
-
[](https://codeclimate.com/github/DannyBen/getcomments/test_coverage)
|
8
7
|
|
9
8
|
---
|
10
9
|
|
@@ -22,7 +21,7 @@ $ gem install getcomments
|
|
22
21
|
|
23
22
|
Or with bundler:
|
24
23
|
|
25
|
-
```
|
24
|
+
```
|
26
25
|
gem 'getcomments'
|
27
26
|
```
|
28
27
|
|
@@ -30,15 +29,36 @@ gem 'getcomments'
|
|
30
29
|
Usage
|
31
30
|
--------------------------------------------------
|
32
31
|
|
32
|
+
Get comments from a file:
|
33
|
+
|
33
34
|
```ruby
|
35
|
+
# GetComments.from_file
|
34
36
|
require 'getcomments'
|
35
|
-
comments = GetComments
|
36
|
-
|
37
|
+
comments = GetComments.from_file 'spec/fixtures/minimal.rb'
|
38
|
+
comments.each do |key, value|
|
39
|
+
puts "#{key}: #{value}"
|
40
|
+
end
|
41
|
+
|
42
|
+
#=> module TestModule: Module comment
|
43
|
+
#=> class TestClass: Class comment
|
44
|
+
#=> attr_reader :some_attr: Attribute comment
|
45
|
+
#=> def some_method: Method comment
|
46
|
+
```
|
47
|
+
|
48
|
+
Get coimments from a string:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# GetComments.from_string
|
52
|
+
code = <<-EOF
|
53
|
+
# This function just sits here
|
54
|
+
def the_function
|
55
|
+
end
|
56
|
+
EOF
|
37
57
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# }
|
58
|
+
comments = GetComments.from_string code
|
59
|
+
comments.each do |key, value|
|
60
|
+
puts "#{key}: #{value}"
|
61
|
+
end
|
43
62
|
|
63
|
+
#=> def the_function: This function just sits here
|
44
64
|
```
|
data/lib/getcomments.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
module GetComments
|
2
|
-
class
|
3
|
-
attr_reader :
|
4
|
-
attr_accessor :comment_index
|
2
|
+
class Code
|
3
|
+
attr_reader :code, :comment_index
|
5
4
|
|
6
|
-
def
|
7
|
-
|
5
|
+
def initialize(code)
|
6
|
+
@code = code
|
7
|
+
@comment_index = 0
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
@
|
12
|
-
@comment_index = 0
|
10
|
+
def comments
|
11
|
+
@comments ||= comments!
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
private
|
15
|
+
|
16
|
+
def comments!
|
16
17
|
last_comment = []
|
17
18
|
result = {}
|
18
19
|
|
@@ -34,19 +35,18 @@ module GetComments
|
|
34
35
|
result
|
35
36
|
end
|
36
37
|
|
37
|
-
private
|
38
|
-
|
39
38
|
def lines
|
40
|
-
@lines ||=
|
39
|
+
@lines ||= code.lines
|
41
40
|
end
|
42
41
|
|
43
42
|
def get_key(line='')
|
44
43
|
if match = line.match(/^([\w_]+ [\w\:]+)/)
|
45
44
|
match.captures.first
|
46
45
|
else
|
47
|
-
|
46
|
+
@comment_index += 1
|
48
47
|
"comment_#{comment_index}"
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
52
|
-
|
51
|
+
|
52
|
+
end
|
data/lib/getcomments/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getcomments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Extract comments from a Ruby source file
|
14
14
|
email: db@dannyben.com
|
@@ -18,7 +18,7 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- README.md
|
20
20
|
- lib/getcomments.rb
|
21
|
-
- lib/getcomments/
|
21
|
+
- lib/getcomments/code.rb
|
22
22
|
- lib/getcomments/version.rb
|
23
23
|
homepage: https://github.com/DannyBen/getcomments
|
24
24
|
licenses:
|
@@ -39,8 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
|
-
|
43
|
-
rubygems_version: 2.7.6
|
42
|
+
rubygems_version: 3.0.3
|
44
43
|
signing_key:
|
45
44
|
specification_version: 4
|
46
45
|
summary: Extract comments from a Ruby source file
|