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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81f3c63a29fc5da2d5720ed6ffd18a3f7b0839c0e225ddb54c0f8fb0cbdc1461
4
- data.tar.gz: d2f56c1df54c246104cd1feeeb23bd58d48c3aeb35ea4c3c86dba2d18f10ba44
3
+ metadata.gz: 1c302859eeba8bb1f91ee222ced925aa24a5e9fef97f2485db3c5f7a14defe4c
4
+ data.tar.gz: bf5f7894e2bb22879ad1e7c4fa045b7b21369be02ea18a99e992c46bb5b3ae9c
5
5
  SHA512:
6
- metadata.gz: 6b38b6258c8c5ea428253c33fa9ecad90649b522f8e33cf2cb4ad0b31a525c1aaaa90737475c857b1c77c2bc4599a0ac07a078971711da81f0a48484301e74b6
7
- data.tar.gz: 38eaf21fb04cd582938abfcd932e2b376ad66fee466222e6c45bcbdc575d48808b8403f67feef72ed67c7e273ac3f8b0e0d0c942b8ed7ade80a0b157e5fa34fa
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
  [![Gem Version](https://badge.fury.io/rb/getcomments.svg)](https://badge.fury.io/rb/getcomments)
5
5
  [![Build Status](https://travis-ci.com/DannyBen/getcomments.svg?branch=master)](https://travis-ci.com/DannyBen/getcomments)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/bcf41ae9f2c8ebd59f4d/maintainability)](https://codeclimate.com/github/DannyBen/getcomments/maintainability)
7
- [![Test Coverage](https://api.codeclimate.com/v1/badges/bcf41ae9f2c8ebd59f4d/test_coverage)](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
- ```ruby
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::Read.from 'filename.rb'
36
- p comments
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
- # "module TestModule" => "This is the module comment",
40
- # "class TestClass" => "This is the class comment",
41
- # "def some_method" => "This is a multiline\nmethod comment"
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
  ```
@@ -1,2 +1,12 @@
1
1
  require 'getcomments/version'
2
- require 'getcomments/read'
2
+ require 'getcomments/code'
3
+
4
+ module GetComments
5
+ def self.from_file(filename)
6
+ from_string(File.read filename)
7
+ end
8
+
9
+ def self.from_string(code)
10
+ Code.new(code).comments
11
+ end
12
+ end
@@ -1,18 +1,19 @@
1
1
  module GetComments
2
- class Read
3
- attr_reader :filename
4
- attr_accessor :comment_index
2
+ class Code
3
+ attr_reader :code, :comment_index
5
4
 
6
- def self.from(filename)
7
- new(filename).get
5
+ def initialize(code)
6
+ @code = code
7
+ @comment_index = 0
8
8
  end
9
9
 
10
- def initialize(filename)
11
- @filename = filename
12
- @comment_index = 0
10
+ def comments
11
+ @comments ||= comments!
13
12
  end
14
13
 
15
- def get
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 ||= File.readlines filename
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
- self.comment_index += 1
46
+ @comment_index += 1
48
47
  "comment_#{comment_index}"
49
48
  end
50
49
  end
51
50
  end
52
- end
51
+
52
+ end
@@ -1,3 +1,3 @@
1
1
  module GetComments
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-01-11 00:00:00.000000000 Z
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/read.rb
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
- rubyforge_project:
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