tom_extract 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: 3618ce8f6b1fb3e83c83aabb49df8d019137dbcf
4
+ data.tar.gz: d10a68619695b24f2f26928288782b18b4fb23b5
5
+ SHA512:
6
+ metadata.gz: eee837acbe0963f83c8a4cd46a4f9ca7a5366b0a3c6d9984f513049afcbc48d1bee2d1b3b6810fa37873c9b3ef5d832ffa78d61655f320ed855e85017f5cc692
7
+ data.tar.gz: 755ac2c01551e2554f0d3bb4dca77dde8e3041026f9d055d2900a9bf650a9cb7d071fb645112d1ecda692a652b738905e6ed0d244e6d1fad87290a44283be82d
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
19
+ .rspec
20
+ *~
21
+ *\#
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tom_extract.gemspec
4
+ gemspec
5
+
6
+ gem "sexp_info"
7
+
8
+ group :debug do
9
+ gem 'pry_debug'
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 svs
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # TomExtract
2
+
3
+ TomExtract extracts TomDoc from Ruby source files. It provides the answer as a nice Hash. i.e.
4
+
5
+ given a source file like this
6
+
7
+ ```ruby
8
+ module Foo
9
+ class Bar
10
+
11
+ # Public: Duplicate some text an arbitrary number of times.
12
+ #
13
+ # text - The String to be duplicated.
14
+ # count - The Integer number of times to duplicate the text.
15
+ #
16
+ # Examples
17
+ #
18
+ # multiplex('Tom', 4)
19
+ # # => 'TomTomTomTom'
20
+ #
21
+ # Returns the duplicated String.
22
+ def multiplex(text, count)
23
+ text * count
24
+ end
25
+ end
26
+ end
27
+ ```
28
+ it provides the following data
29
+
30
+ ```ruby
31
+ { "Foo" => {
32
+ "Bar" => {
33
+ "multiplex" => " # Public: Duplicate some text an arbitrary number of times.
34
+ #
35
+ # text - The String to be duplicated.
36
+ # count - The Integer number of times to duplicate the text.
37
+ #
38
+ # Examples
39
+ #
40
+ # multiplex('Tom', 4)
41
+ # # => 'TomTomTomTom'
42
+ #
43
+ # Returns the duplicated String."
44
+ }
45
+ }
46
+ }
47
+ }
48
+ ```
49
+
50
+
51
+ ## Installation
52
+
53
+ Add this line to your application's Gemfile:
54
+
55
+ gem 'tom_extract'
56
+
57
+ And then execute:
58
+
59
+ $ bundle
60
+
61
+ Or install it yourself as:
62
+
63
+ $ gem install tom_extract
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = ""
6
+ end
7
+
8
+ task :default => ["spec"]
@@ -0,0 +1,46 @@
1
+ require "bundler/setup"
2
+ require "sexp_info"
3
+ require "tom_extract/version"
4
+ require "tom_extract/comment_extractor"
5
+ require 'ripper'
6
+ require 'pry_debug'
7
+
8
+ class TomExtract
9
+
10
+ def initialize(pathname)
11
+ @pathname = Pathname.new(pathname)
12
+ end
13
+
14
+ def result
15
+ extract_methods
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :pathname
21
+
22
+ def source
23
+ File.read(pathname)
24
+ end
25
+
26
+ def extract_methods(h = sexp_info.to_h)
27
+ Hash[
28
+ h.map do |name, item|
29
+ [name, item.is_a?(SexpThing::Def) ? method_with_comments(item) : (item.is_a?(Hash) ? extract_methods(item) : nil)]
30
+ end.reject{|k,v| k == :sexp}
31
+ ]
32
+ end
33
+
34
+ def method_with_comments(m)
35
+ CommentExtractor.new(pathname, m.line_number).comment
36
+ end
37
+
38
+ def sexp
39
+ Ripper.sexp(source)
40
+ end
41
+
42
+ def sexp_info
43
+ @sexp_info ||= SexpInfo.new(sexp)
44
+ end
45
+
46
+ end
@@ -0,0 +1,24 @@
1
+ class CommentExtractor
2
+
3
+ def initialize(pathname, line_number)
4
+ @pathname, @line_number = pathname, line_number
5
+ end
6
+
7
+ def comment
8
+ c = []
9
+ source[0..(line_number-2)].reverse.each do |l|
10
+ break if l.gsub(/\s/,'').empty?
11
+ c << l if l.match(/\A\s*\#/)
12
+ end
13
+ c.reverse.join("\n")
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :pathname, :line_number
19
+
20
+ def source
21
+ File.read(pathname).split("\n")
22
+ end
23
+
24
+ end
@@ -0,0 +1,3 @@
1
+ class TomExtract
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ module Foo
2
+ class Bar
3
+
4
+ # Public: Duplicate some text an arbitrary number of times.
5
+ #
6
+ # text - The String to be duplicated.
7
+ # count - The Integer number of times to duplicate the text.
8
+ #
9
+ # Examples
10
+ #
11
+ # multiplex('Tom', 4)
12
+ # # => 'TomTomTomTom'
13
+ #
14
+ # Returns the duplicated String.
15
+ def multiplex(text, count)
16
+ text * count
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ require 'tom_extract'
2
+
3
+ describe CommentExtractor do
4
+
5
+ subject { CommentExtractor.new('./spec/fixtures/source.rb', 15) }
6
+
7
+
8
+ its(:comment) { should == " # Public: Duplicate some text an arbitrary number of times.
9
+ #
10
+ # text - The String to be duplicated.
11
+ # count - The Integer number of times to duplicate the text.
12
+ #
13
+ # Examples
14
+ #
15
+ # multiplex('Tom', 4)
16
+ # # => 'TomTomTomTom'
17
+ #
18
+ # Returns the duplicated String." }
19
+
20
+ end
@@ -0,0 +1,27 @@
1
+ require 'tom_extract'
2
+
3
+
4
+ describe TomExtract do
5
+
6
+ subject { TomExtract.new('./spec/fixtures/source.rb') }
7
+
8
+ its(:result) { should ==
9
+ { "Foo" => {
10
+ "Bar" => {
11
+ "multiplex" => " # Public: Duplicate some text an arbitrary number of times.
12
+ #
13
+ # text - The String to be duplicated.
14
+ # count - The Integer number of times to duplicate the text.
15
+ #
16
+ # Examples
17
+ #
18
+ # multiplex('Tom', 4)
19
+ # # => 'TomTomTomTom'
20
+ #
21
+ # Returns the duplicated String."
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tom_extract/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tom_extract"
8
+ spec.version = TomExtract::VERSION
9
+ spec.authors = ["svs"]
10
+ spec.email = ["svs@svs.io"]
11
+ spec.description = %q{Extract TomDoc from a source file}
12
+ spec.summary = %q{Does what it says on the tin.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ # spec.add_dependency "sexp_info"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tom_extract
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - svs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Extract TomDoc from a source file
56
+ email:
57
+ - svs@svs.io
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/tom_extract.rb
69
+ - lib/tom_extract/comment_extractor.rb
70
+ - lib/tom_extract/comment_extractor.rb~
71
+ - lib/tom_extract/version.rb
72
+ - spec/fixtures/source.rb
73
+ - spec/lib/comment_extractor_spec.rb
74
+ - spec/lib/tom_extract_spec.rb
75
+ - tom_extract.gemspec
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Does what it says on the tin.
100
+ test_files:
101
+ - spec/fixtures/source.rb
102
+ - spec/lib/comment_extractor_spec.rb
103
+ - spec/lib/tom_extract_spec.rb