getcomments 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01cd40028f263855c57e550e4c2578ecc7859ce1
4
+ data.tar.gz: e4eb10535f97759162a02144138bc24a0b196c17
5
+ SHA512:
6
+ metadata.gz: 20cb117d9bf0af5f9af33bf59ccf01651c33eccb75aaba462f5bd8a2b0adf7d73f5a9f8e1f1c979e50cdc8aa08ba8f06dc8e899bc2eedb3f9b13767481e14816
7
+ data.tar.gz: 0a705f0c77c0406cb5be02f4fe6c75edd81fde797ccaaad27c63dd7c736db6e85539f12bbe179309ed6ef1e76511c698a8597f1f4d6c17922b8f7219d84cefb5
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ GetComments - Extract Comments from Ruby Code
2
+ ==================================================
3
+
4
+ [![Gem](https://img.shields.io/gem/v/getcomments.svg?style=flat-square)](https://rubygems.org/gems/getcomments)
5
+ [![Travis](https://img.shields.io/travis/DannyBen/getcomments.svg?style=flat-square)](https://travis-ci.org/DannyBen/getcomments)
6
+ [![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/getcomments.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/getcomments)
7
+ [![Gemnasium](https://img.shields.io/gemnasium/DannyBen/getcomments.svg?style=flat-square)](https://gemnasium.com/DannyBen/getcomments)
8
+
9
+ ---
10
+
11
+ This library provides an easy way to extract comments from a ruby source file.
12
+
13
+ ---
14
+
15
+
16
+ Install
17
+ --------------------------------------------------
18
+
19
+ ```
20
+ $ gem install getcomments
21
+ ```
22
+
23
+ Or with bundler:
24
+
25
+ ```ruby
26
+ gem 'getcomments'
27
+ ```
28
+
29
+
30
+ Usage
31
+ --------------------------------------------------
32
+
33
+ ```ruby
34
+ require 'getcomments'
35
+ comments = GetComments::Read.from 'filename.rb'
36
+ p comments
37
+
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
+ }
43
+
44
+ ```
@@ -0,0 +1,2 @@
1
+ require 'getcomments/version'
2
+ require 'getcomments/read'
@@ -0,0 +1,48 @@
1
+ module GetComments
2
+ class Read
3
+ attr_reader :filename
4
+
5
+ def self.from(filename)
6
+ new(filename).get
7
+ end
8
+
9
+ def initialize(filename)
10
+ @filename = filename
11
+ end
12
+
13
+ def get
14
+ last_comment = []
15
+ result = {}
16
+
17
+ lines.each do |line|
18
+ line.strip!
19
+
20
+ if line[0] == '#'
21
+ last_comment << line.gsub(/^# ?/, '')
22
+ elsif !last_comment.empty?
23
+ key = get_key line
24
+ result[key] = last_comment.join("\n") if key
25
+ last_comment = []
26
+ end
27
+ end
28
+
29
+ result
30
+ end
31
+
32
+ private
33
+
34
+ def lines
35
+ @lines ||= File.readlines filename
36
+ end
37
+
38
+ def get_key(line)
39
+ key = nil
40
+
41
+ if match = line.match(/^([\w_]+ [\w\:]+)/)
42
+ key = match.captures.first
43
+ end
44
+
45
+ key
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module GetComments
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: getcomments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Danny Ben Shitrit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: runfile
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: runfile-tasks
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-doc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.13'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.13'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ description: Extract comments from a Ruby source file
126
+ email: db@dannyben.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - README.md
132
+ - lib/getcomments.rb
133
+ - lib/getcomments/read.rb
134
+ - lib/getcomments/version.rb
135
+ homepage: https://github.com/DannyBen/getcomments
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: 2.0.0
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.6.6
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Extract comments from a Ruby source file
159
+ test_files: []