comment_collector 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
+ SHA256:
3
+ metadata.gz: fd7163400e0f5dad62167c657187a19b3b7d86d19aad2f3c2d878190e22a0853
4
+ data.tar.gz: 8ec29610159563a21f8d5c70d28e1b76894912c636a6a3c893f86b936781c133
5
+ SHA512:
6
+ metadata.gz: cbf8a96d9f0c327db8f7eb8423319eda02f7c92ddf0d08571ce611dc15986642d247115b2ddb2f2e329417b298a609afd37b4d8f1ed6af4721452758288b4512
7
+ data.tar.gz: 76faf9432d6f64ea29a309a4238a9de4ce5de213dbf9013e3f38ec9a87154f7cf6155ffda91ec67553d3d342a046bc9f07661b10d8d26bfb2b88203dbd0db169
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - ruby-2.6.0-preview2
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tmshuichi@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in comment_collector.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ comment_collector (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.7.0)
12
+ rspec-core (~> 3.7.0)
13
+ rspec-expectations (~> 3.7.0)
14
+ rspec-mocks (~> 3.7.0)
15
+ rspec-core (3.7.1)
16
+ rspec-support (~> 3.7.0)
17
+ rspec-expectations (3.7.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-mocks (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-support (3.7.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ comment_collector!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Shuichi Tamayose
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # CommentCollector
2
+
3
+ Get source code comments of Ruby.
4
+
5
+ require RUBY_VERSION >= '2.6.0'
6
+
7
+
8
+ ## Installation
9
+
10
+ Or install it yourself as:
11
+
12
+ ```
13
+ $ gem install comment_collector
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ `example.rb`
19
+
20
+ ```ruby
21
+ # class comment
22
+ # this is sample
23
+ class Foo
24
+ BAR = 'hello' # string
25
+
26
+ # method
27
+ def say
28
+ 'hi'
29
+ end
30
+ end
31
+
32
+ =begin
33
+ multi line
34
+ commens
35
+ =end
36
+ ```
37
+
38
+ `comment.rb`
39
+
40
+ ```ruby
41
+ require 'comment_collector'
42
+
43
+ comments = CommentCollector.get(File.read('example.rb'))
44
+
45
+ puts '=' * 20
46
+
47
+ comments.each do |comment|
48
+ puts comment.value
49
+ puts '=' * 20
50
+ end
51
+ ```
52
+
53
+ result
54
+
55
+ ```
56
+ $ ruby comment.rb
57
+ ====================
58
+ # class comment
59
+ # this is sample
60
+ ====================
61
+ # string
62
+ ====================
63
+ # method
64
+ ====================
65
+ =begin
66
+ multi line
67
+ commens
68
+ =end
69
+ ====================
70
+ ```
71
+
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
76
+
77
+ ## Code of Conduct
78
+
79
+ Everyone interacting in the CommentCollector project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/comment_collector/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "comment_collector"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'comment_collector/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'comment_collector'
7
+ spec.version = CommentCollector::VERSION
8
+ spec.authors = ['Shuichi Tamayose']
9
+ spec.email = ['tmshuichi@gmail.com']
10
+
11
+ spec.summary = %q{Commenct collector}
12
+ spec.description = %q{Commenct collector}
13
+ spec.homepage = 'https://github.com/siman-man/comment_collector'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '> 2.5.9'
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ end
@@ -0,0 +1,92 @@
1
+ require 'comment_collector/version'
2
+
3
+ class CommentCollector
4
+ Comment = Struct.new(:value, :first_lineno, :first_column, :last_lineno, :last_column)
5
+
6
+ def self.get(src)
7
+ new(src).comments
8
+ end
9
+
10
+ def initialize(src)
11
+ @last_of_lines = Array.new(src.lines.size, 0)
12
+ @exists_any_node = Array.new(src.lines.size, false)
13
+ @end_of_lines = src.lines.map { |l| l.size - 1 } # for 0-index
14
+ @src = src
15
+
16
+ traverse(RubyVM::AST.parse(src))
17
+ end
18
+
19
+ def comments
20
+ return @_comments if defined?(@_comments)
21
+ comments = []
22
+ value = ''
23
+ multi_line_comment_f = false
24
+ first_lineno = -1
25
+ first_column = -1
26
+ last_lineno = -1
27
+
28
+ @src.lines.each_with_index do |line, lineno|
29
+ sp = @last_of_lines[lineno]
30
+ l = line[sp..]
31
+
32
+ break if line.start_with?('__END__')
33
+
34
+ if l =~ /^\s*#/
35
+ if value.empty?
36
+ first_lineno = lineno
37
+ first_column = sp + l.index('#')
38
+ value = l.lstrip
39
+ elsif sp.zero?
40
+ value += l
41
+ else
42
+ comments << Comment.new(value, first_lineno, first_column, last_lineno, @end_of_lines[last_lineno])
43
+ first_lineno = lineno
44
+ first_column = sp + l.index('#')
45
+ value = l.lstrip
46
+ end
47
+
48
+ last_lineno = lineno
49
+ elsif l =~ /^=begin/
50
+ value = l
51
+ first_lineno = lineno
52
+ first_column = 0
53
+ multi_line_comment_f = true
54
+ elsif l =~ /^=end/
55
+ value += l
56
+ comments << Comment.new(value, first_lineno, first_column, lineno, @end_of_lines[lineno])
57
+ value = ''
58
+ multi_line_comment_f = false
59
+ elsif multi_line_comment_f
60
+ value += l
61
+ elsif !value.empty? && (line =~ /^\s+$/ || @exists_any_node[lineno])
62
+ comments << Comment.new(value, first_lineno, first_column, last_lineno, @end_of_lines[last_lineno])
63
+ value = ''
64
+ end
65
+ end
66
+
67
+ unless value.empty?
68
+ comments << Comment.new(value, first_lineno, first_column, last_lineno, @end_of_lines[last_lineno])
69
+ end
70
+
71
+ @_comments = comments
72
+ end
73
+
74
+ private
75
+
76
+ def traverse(parent)
77
+ if parent.type != 'NODE_SCOPE'
78
+ first_lineno = parent.first_lineno - 1
79
+ first_column = parent.first_column
80
+ last_lineno = parent.last_lineno - 1
81
+ last_column = parent.last_column
82
+
83
+ @last_of_lines[first_lineno] = [@last_of_lines[first_lineno], first_column].max
84
+ @last_of_lines[last_lineno] = [@last_of_lines[last_lineno], last_column].max
85
+ @exists_any_node[first_lineno] = @exists_any_node[last_lineno] = true
86
+ end
87
+
88
+ parent.children.compact.each do |child|
89
+ traverse(child)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ class CommentCollector
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comment_collector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shuichi Tamayose
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEPDCCAqSgAwIBAgIBATANBgkqhkiG9w0BAQsFADAkMSIwIAYDVQQDDBl0bXNo
14
+ dWljaGkvREM9Z21haWwvREM9Y29tMB4XDTE4MDYwNTEwNDMxNloXDTE5MDYwNTEw
15
+ NDMxNlowJDEiMCAGA1UEAwwZdG1zaHVpY2hpL0RDPWdtYWlsL0RDPWNvbTCCAaIw
16
+ DQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAO1YxdwwyCxpUsYMJrCHkAEJKPro
17
+ xsUMzsYu70ZGuJRROQvIVXt5VRm11/K5MqUxOfJ29zcb+NGmR1bu7VgTnfV2LUQ+
18
+ 3n23us1uK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wod0fF+nUUtuGvVgLg9Ma5KE8
34
+ qhBmALr0zPrR292f2IxpPPpA3EGv375Yy0dblIxJ2U0C0p2JafJlIbdzTttaG+nR
35
+ hYkTSRBLdxDTa7SbFGW40+TWobTOX/itwk9w0F6Zo7Y=
36
+ -----END CERTIFICATE-----
37
+ date: 2018-06-18 00:00:00.000000000 Z
38
+ dependencies:
39
+ - !ruby/object:Gem::Dependency
40
+ name: bundler
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.16'
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.16'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '10.0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '10.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '3.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '3.0'
81
+ description: Commenct collector
82
+ email:
83
+ - tmshuichi@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - ".gitignore"
89
+ - ".rspec"
90
+ - ".travis.yml"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - comment_collector.gemspec
100
+ - lib/comment_collector.rb
101
+ - lib/comment_collector/version.rb
102
+ homepage: https://github.com/siman-man/comment_collector
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">"
113
+ - !ruby/object:Gem::Version
114
+ version: 2.5.9
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.7
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Commenct collector
126
+ test_files: []
metadata.gz.sig ADDED
Binary file