comment_extractor 1.0.1 → 1.0.2

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
  SHA1:
3
- metadata.gz: 81a66d3881e6e790f7b4fbd5626661f6b6b7ebce
4
- data.tar.gz: eef85195b570687ca4e6eafbbe841de336884233
3
+ metadata.gz: 26dd72ab6442793761943f54fb4c9763ebbadc21
4
+ data.tar.gz: cd8e371d7e38412c592bf6a23ab9023b2a043379
5
5
  SHA512:
6
- metadata.gz: 918fd7799b29841b8d1ca3a23329ba8c59f48635806dfb29b68e993ec85f20150fe33170db4eb3c228b2d7326503ac76726fca9bbe06f364eac489e81c84d0d2
7
- data.tar.gz: ee4337e67ac7c371d0cad3b83991b379b9d0dcc97e4c709935750b82fc277b75107d4874272876c9954a30dc893f7be16b901e93ca5a6242afe0610d5b11cfe6
6
+ metadata.gz: f0b73f0e94de1f7cc1b6436fe781aa671192216b6f86a8536619d334161b4a51a1ed042111d1763d3a22f7975c09e7e3ee748d623e5c5c3c44c7ad0fb2de1bfb
7
+ data.tar.gz: 2f6f6267f30da17410eddba615cc1b8f6b2e8fe295fb6360ac17f54ea012c85072d72ed8bd4608c882413423126580a27b3c082c3e8b1f80aabc84dea534e6fa
data/README.md CHANGED
@@ -47,17 +47,14 @@ end
47
47
  require 'comment_extractor'
48
48
 
49
49
  file_path = 'path/to/file.rb'
50
- manager = CommentExtractor::ExtractorManager
51
- if extractor = manager.can_extract(file_path)
52
- content = File.read(file_path)
53
- comments = extractor.new(content).extract_comments
54
- comemnts.is_a?(CommentExtractor::CodeObjects)
50
+ if extractor = CommentExtractor::Extractors.find_by_filetype('ruby')
51
+ parser = CommentExtractor::Parser.initialize_with_extractor(file_path, extractor)
52
+ comments = parser.extract_comments
55
53
  end
56
54
 
57
55
  # Other way to find extractor
58
- extractor = manager.find_extractor_by_shebang('#! /usr/local/bin/ruby')
59
- extractor = manager.find_extractor_by_filename('path/to/file.rb')
60
- extractor = manager.find_extractor_by_filetype('ruby')
56
+ extractor = CommentExtractor::Extractors.find_by_shebang('#! /usr/local/bin/ruby')
57
+ extractor = CommentExtractor::Extractors.find_by_filename('path/to/file.rb')
61
58
  ```
62
59
 
63
60
  #### How to use extractor of specific filetype.
@@ -65,7 +62,8 @@ extractor = manager.find_extractor_by_filetype('ruby')
65
62
  ```ruby
66
63
  require 'comment_extractor/extractor/d'
67
64
 
68
- content = File.read('path/to/file.d')
65
+ # Remove shebang and encoding content
66
+ content = CommentExtractor::File.open('path/to/file.d', 'r') { |f| f.read_content }
69
67
  comments = CommentExtractor::Extractor::D.new(content).extract_comments
70
68
  ```
71
69
 
@@ -2,7 +2,7 @@ require 'comment_extractor/code_object'
2
2
  require 'comment_extractor/configuration'
3
3
  require 'comment_extractor/encoding'
4
4
  require 'comment_extractor/extractor'
5
- require 'comment_extractor/extractor_manager'
5
+ require 'comment_extractor/extractors'
6
6
  require 'comment_extractor/file'
7
7
  require 'comment_extractor/parser'
8
8
  require 'comment_extractor/version'
@@ -1,44 +1,51 @@
1
- require 'comment_extractor/extractor_manager'
1
+ require 'comment_extractor/extractors'
2
2
  require 'comment_extractor/extractor/text'
3
3
 
4
4
  module CommentExtractor
5
5
  class Configuration
6
- @@required_attributes = {}
7
-
8
6
  def initialize(attributes = {})
7
+ required_attributes = self.class.required_attributes.dup
8
+
9
9
  attributes.each do |key, value|
10
- method_name = "#{key}="
11
- send(method_name, value) if respond_to?(method_name)
10
+ required_attributes.delete(key)
11
+ send("#{key}=", value)
12
12
  end
13
13
 
14
- @@required_attributes.each_key do |key|
15
- raise "Unable to initialize #{key} without attribute" unless self.send(key)
14
+ unless required_attributes.empty?
15
+ keys = required_attributes.keys.map { |v| ":#{v}" }.join(', ')
16
+ raise ArgumentError, "Unable to initialize #{keys} without attribute"
16
17
  end
17
18
 
18
- self.extractors = ExtractorManager.default_extractors
19
- self.default_extractor = Extractor::Text
20
- self.use_default_extractor = true
19
+ @extractors = Extractors.default_extractors
20
+ @default_extractor = Extractor::Text
21
+ @use_default_extractor = true
21
22
  end
22
23
 
23
- def self.add_setting(name, opts={})
24
- attr_accessor name
24
+ class << self
25
+ def add_setting(name, opts={})
26
+ attr_accessor name
25
27
 
26
- define_predicate_for(name) if opts.delete(:predicate)
27
- define_required_attribute(name) if opts.delete(:required)
28
- end
28
+ define_predicating_for(name) if opts.delete(:predicate)
29
+ define_required_attribute(name) if opts.delete(:required)
30
+ end
29
31
 
30
- private
32
+ def required_attributes
33
+ @required_attributes ||= {}
34
+ end
35
+
36
+ private
31
37
 
32
- def self.define_required_attribute(*names)
33
- names.each do |name|
34
- @@required_attributes[name] = nil
38
+ def define_required_attribute(*names)
39
+ names.each do |name|
40
+ required_attributes[name] = nil
41
+ end
35
42
  end
36
- end
37
43
 
38
- def self.define_predicate_for(*names)
39
- names.each do |name|
40
- define_method "#{name}?" do
41
- !!send(name)
44
+ def define_predicating_for(*names)
45
+ names.each do |name|
46
+ define_method "#{name}?" do
47
+ !!send(name)
48
+ end
42
49
  end
43
50
  end
44
51
  end
@@ -28,6 +28,8 @@ module CommentExtractor
28
28
  end
29
29
 
30
30
  content
31
+ rescue ArgumentError
32
+ nil
31
33
  end
32
34
 
33
35
  private
@@ -1,6 +1,4 @@
1
- require 'comment_extractor/smart_string_scanner'
2
-
3
- using CommentExtractor::SmartStringScanner
1
+ require 'comment_extractor/string_scanner'
4
2
 
5
3
  class CommentExtractor::Extractor
6
4
  module Concerns
@@ -34,6 +32,7 @@ class CommentExtractor::Extractor
34
32
 
35
33
  def comment(start_with: nil, end_with: nil, type: ONE_LINER_COMMENT)
36
34
  @comment_regexp ||= []
35
+ # Check required attributes
37
36
  raise ArgumentError unless [type, start_with].all?
38
37
 
39
38
  definition = { start_with: build_regexp(start_with), type: type, end_with: end_with }
@@ -41,6 +40,7 @@ class CommentExtractor::Extractor
41
40
  if type == BLOCK_COMMENT
42
41
  definition[:end_with] = build_regexp(end_with, Regexp::MULTILINE)
43
42
  end
43
+
44
44
  @comment_regexp << definition
45
45
  end
46
46
 
@@ -51,13 +51,13 @@ class CommentExtractor::Extractor
51
51
 
52
52
  def define_bracket(bracket, options = 0)
53
53
  start_regexp = build_regexp(bracket)
54
- stop_regexp = if bracket.is_a?(Regexp)
54
+ end_regexp = if bracket.is_a?(Regexp)
55
55
  join_regexp(/(?<!\\)/, bracket)
56
56
  else
57
57
  /(?<!\\)#{bracket}/
58
58
  end
59
- stop_regexp = Regexp.new(stop_regexp.source, options)
60
- append_bracket(start_regexp, stop_regexp)
59
+ end_regexp = Regexp.new(end_regexp.source, options)
60
+ append_bracket(start_regexp, end_regexp)
61
61
  end
62
62
 
63
63
  def define_regexp_bracket
@@ -129,8 +129,9 @@ class CommentExtractor::Extractor
129
129
  end_with = definition[:end_with]
130
130
  next unless scanner.scan(start_with)
131
131
 
132
- new_regexp = Regexp.new(/.*?/.source + end_with.source, end_with.options)
133
- return scanner.scan(new_regexp)
132
+ end_with_source = /.*?/.source + end_with.source
133
+ end_with_regexp = Regexp.new(end_with_source, end_with.options)
134
+ return scanner.scan(end_with_regexp)
134
135
  end
135
136
 
136
137
  nil
@@ -167,18 +168,17 @@ class CommentExtractor::Extractor
167
168
  line_number = scanner.current_line
168
169
  comment = scanner.scan(/^.*$/)
169
170
  metadata = { type: ONE_LINER_COMMENT }
170
- comment_object = build_comment(line_number, comment, **metadata)
171
171
 
172
- code_objects << comment_object
172
+ code_objects << build_comment(line_number, comment, **metadata)
173
173
  end
174
174
 
175
175
  def identify_multi_line_comment(regexp)
176
176
  line_no = scanner.current_line
177
177
  stop_regexp = Regexp.new(/.*?/.source + regexp.source, regexp.options)
178
- comment_block = scanner.scan(stop_regexp)
178
+ block_comment = scanner.scan(stop_regexp)
179
179
 
180
180
  remove_tail_regexp = Regexp.new(regexp.source + /$/.source)
181
- comments = comment_block.sub(remove_tail_regexp, '').split("\n")
181
+ comments = block_comment.sub(remove_tail_regexp, '').split("\n")
182
182
  comments.each_with_index do |comment, index|
183
183
  metadata = { type: BLOCK_COMMENT }
184
184
  code_objects << build_comment(line_no + index, comment, metadata)
@@ -2,10 +2,8 @@ require 'comment_extractor'
2
2
  require 'comment_extractor/extractor'
3
3
  require 'comment_extractor/file'
4
4
 
5
- using CommentExtractor::DetectableSchemeFile
6
-
7
5
  module CommentExtractor
8
- module ExtractorManager
6
+ module Extractors
9
7
  class << self
10
8
  def default_extractors
11
9
  %i[
@@ -39,11 +37,11 @@ module CommentExtractor
39
37
 
40
38
  extractor = nil
41
39
  if shebang = File.shebang(file_path)
42
- extractor = find_extractor_by_shebang(shebang)
40
+ extractor = find_by_shebang(shebang)
43
41
  end
44
42
 
45
43
  unless extractor
46
- extractor = find_extractor_by_filename(file_path)
44
+ extractor = find_by_filename(file_path)
47
45
  end
48
46
 
49
47
  if ::CommentExtractor.configuration.use_default_extractor
@@ -63,8 +61,8 @@ module CommentExtractor
63
61
  defined_extractor_finders.concat(keys)
64
62
 
65
63
  keys.each do |key|
66
- define_singleton_method "find_extractor_by_#{key}" do |value|
67
- find_extractor_by(key, value)
64
+ define_singleton_method "find_by_#{key}" do |value|
65
+ find_by(key, value)
68
66
  end
69
67
  end
70
68
  end
@@ -77,7 +75,7 @@ module CommentExtractor
77
75
  self
78
76
  end
79
77
 
80
- def find_extractor_by(key, value)
78
+ def find_by(key, value)
81
79
  case key
82
80
  when :filename, :shebang
83
81
  # Regexp optimization which can find value O(1)
@@ -152,7 +150,7 @@ module CommentExtractor
152
150
  end
153
151
  end
154
152
 
155
- # define :find_extractor_by_shebang, :find_extractor_by_filename
153
+ # define :find_by_shebang, :find_by_filename
156
154
  define_extractor_finder_by *Extractor::SCHAME_ACCESSOR_NAMES
157
155
  end
158
156
  end
@@ -1,42 +1,39 @@
1
1
  require 'comment_extractor/encoding'
2
2
 
3
3
  module CommentExtractor
4
- module DetectableSchemeFile
4
+ class File < ::File
5
5
  THRESHOLD_BINARY = 0.3
6
6
 
7
- refine File do
8
- attr_accessor :content, :shebang
7
+ attr_accessor :content, :shebang
9
8
 
10
- # [review] - How can I refine class method?
11
- def File.shebang(path)
12
- if File.extname(path).empty?
13
- line = File.open(path) { |f| f.gets }
14
- if /\A#!\s*(?<shebang_path>.+)/ =~ line
15
- shebang_path
16
- end
9
+ def self.shebang(path)
10
+ if File.extname(path).empty?
11
+ line = File.open(path) { |f| f.gets }
12
+ if /\A#!\s*(?<shebang_path>.+)/ =~ line
13
+ shebang_path
17
14
  end
18
15
  end
16
+ end
19
17
 
20
- def File.binary?(file_path)
21
- header = File.read(file_path, File.stat(file_path).blksize) || nil
18
+ def self.binary?(file_path)
19
+ header = File.read(file_path, File.stat(file_path).blksize) || nil
22
20
 
23
- if header.nil? || header.empty?
24
- false
25
- else
26
- chars = header.chars
27
- (chars.grep(' '..'~').size / chars.size.to_f) <= THRESHOLD_BINARY
28
- end
21
+ if header.nil? || header.empty?
22
+ false
23
+ else
24
+ chars = header.chars
25
+ (chars.grep(' '..'~').size / chars.size.to_f) <= THRESHOLD_BINARY
29
26
  end
27
+ end
30
28
 
31
- def read_content
32
- return if File.binary?(self.path)
33
-
34
- if File.shebang(self.path)
35
- self.gets # Remove shebang
36
- end
29
+ def read_content
30
+ return if File.binary?(self.path)
37
31
 
38
- CommentExtractor::Encoding.encode(self.read)
32
+ if File.shebang(self.path)
33
+ self.gets # Remove shebang
39
34
  end
35
+
36
+ CommentExtractor::Encoding.encode(self.read) || ''
40
37
  end
41
38
  end
42
39
  end
@@ -1,7 +1,5 @@
1
1
  require 'comment_extractor/file'
2
- require 'comment_extractor/extractor_manager'
3
-
4
- using CommentExtractor::DetectableSchemeFile
2
+ require 'comment_extractor/extractors'
5
3
 
6
4
  module CommentExtractor
7
5
  class Parser
@@ -17,17 +15,19 @@ module CommentExtractor
17
15
  raise TypeError, "#{@extractor} should be a instance of #{Extractor}"
18
16
  end
19
17
 
20
- class << self
21
- def for(file_path)
22
- if extractor = ExtractorManager.can_extract(file_path)
23
- content = File.open(file_path, 'r') { |f| f.read_content }
24
-
25
- # Initialize parser
26
- code_objects = CodeObjects.new(file: file_path)
27
- instance_of_extractor = extractor.new(content, code_objects)
28
- new(instance_of_extractor)
29
- end
18
+ def self.for(file_path)
19
+ if extractor = Extractors.can_extract(file_path)
20
+ self.initialize_with_extractor(file_path, extractor)
30
21
  end
31
22
  end
23
+
24
+ def self.initialize_with_extractor(file_path, extractor)
25
+ content = File.open(file_path, 'r') { |f| f.read_content }
26
+
27
+ # Initialize parser
28
+ code_objects = CodeObjects.new(file: file_path)
29
+ instance_of_extractor = extractor.new(content, code_objects)
30
+ new(instance_of_extractor)
31
+ end
32
32
  end
33
33
  end
@@ -0,0 +1,9 @@
1
+ require 'strscan'
2
+
3
+ module CommentExtractor
4
+ class StringScanner < ::StringScanner
5
+ def current_line
6
+ string[0...charpos].count("\n") + 1
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
1
  module CommentExtractor
2
- Version = '1.0.1'
2
+ Version = '1.0.2'
3
3
  VERSION = Version
4
4
  end
@@ -3,32 +3,48 @@ require 'comment_extractor/configuration'
3
3
 
4
4
  module CommentExtractor
5
5
  describe Configuration do
6
+ before do
7
+ # Initializes class variables
8
+ @required_attributes = described_class.instance_variable_set(:@required_attributes, {})
9
+
10
+ described_class.instance_variable_set(:@required_attributes, {})
11
+ end
12
+
13
+ after do
14
+ # Restores class variables
15
+ described_class.instance_variable_set(:@required_attributes, @required_attributes)
16
+ end
17
+
6
18
  describe '.new' do
7
19
  subject { CommentExtractor::Configuration.new(options) }
8
- let(:options) { { root_path: File.dirname(__FILE__) } }
20
+ let(:options) { {} }
9
21
 
10
- it 'sets attributes to default value' do
11
- expect(subject.extractors).to eql ExtractorManager.default_extractors
12
- expect(subject.default_extractor).to eql Extractor::Text
13
- expect(subject.use_default_extractor).to be_truthy
22
+ context 'given valid attributes' do
23
+ it 'sets attributes to default value' do
24
+ expect(subject.extractors).to eql Extractors.default_extractors
25
+ expect(subject.default_extractor).to eql Extractor::Text
26
+ expect(subject.use_default_extractor).to be_truthy
27
+ end
14
28
  end
15
- end
16
29
 
17
- describe '.add_setting' do
18
- before do
19
- # Initializes class variables
20
- @required_attributes = Configuration.class_variable_set(:@@required_attributes, {})
21
- Configuration.class_variable_set(:@@required_attributes, {})
30
+ context 'given invalid attributes' do
31
+ before do
32
+ described_class.add_setting :required_attribute, required: true
33
+ end
22
34
 
23
- Configuration.send(:add_setting, name, option_of_setting)
35
+ it "raises 'Unable to initialize :key without attribute' as #{ArgumentError}" do
36
+ expect { subject }.to raise_error(ArgumentError)
37
+ end
24
38
  end
39
+ end
25
40
 
26
- after do
27
- # Restores class variables
28
- Configuration.class_variable_set(:@@required_attributes, @required_attributes)
41
+ describe '.add_setting' do
42
+ subject { described_class.new(option_of_initialization) }
43
+
44
+ before do
45
+ described_class.send(:add_setting, name, option_of_setting)
29
46
  end
30
47
 
31
- subject { Configuration.new(option_of_initialization) }
32
48
  let(:name) { :setting_name }
33
49
  let(:option_of_setting) { {} }
34
50
  let(:option_of_initialization) { {} }
@@ -53,12 +69,11 @@ module CommentExtractor
53
69
  context 'given required option' do
54
70
  let(:option_of_setting) { { required: true } }
55
71
 
56
- context 'when initializations configuration without required attribute' do
57
- let(:message) { "Unable to initialize #{name} without attribute" }
58
- it { expect { subject }.to raise_error(message) }
72
+ context 'when to initialize configuration without required attribute' do
73
+ it { expect { subject }.to raise_error(ArgumentError) }
59
74
  end
60
75
 
61
- context 'when initializations configuration with required attribute' do
76
+ context 'when to initialize configuration with required attribute' do
62
77
  let(:option_of_initialization) { { name => true } }
63
78
  it { expect { subject }.to_not raise_error }
64
79
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
- require 'comment_extractor/extractor_manager'
2
+ require 'comment_extractor/extractors'
3
3
 
4
4
  module CommentExtractor
5
- describe ExtractorManager do
5
+ describe Extractors do
6
6
  after do
7
7
  if described_class.instance_variable_defined?(:@extractors)
8
8
  described_class.send(:remove_instance_variable, :@extractors)
@@ -74,22 +74,22 @@ module CommentExtractor
74
74
  end
75
75
  end
76
76
 
77
- describe '.find_extractor_by_shebang' do
78
- subject { described_class.find_extractor_by_shebang(test_value) }
77
+ describe '.find_by_shebang' do
78
+ subject { described_class.find_by_shebang(test_value) }
79
79
  let(:registed_value) { '#! /usr/local/ruby' }
80
80
 
81
81
  it_behaves_like 'trying to find extractor'
82
82
  end
83
83
 
84
- describe '.find_extractor_by_filename' do
85
- subject { described_class.find_extractor_by_filename(test_value) }
84
+ describe '.find_by_filename' do
85
+ subject { described_class.find_by_filename(test_value) }
86
86
  let(:registed_value) { 'path/to/file.rb' }
87
87
 
88
88
  it_behaves_like 'trying to find extractor'
89
89
  end
90
90
 
91
- describe '.find_extractor_by_filetype' do
92
- subject { described_class.find_extractor_by_filetype('key') }
91
+ describe '.find_by_filetype' do
92
+ subject { described_class.find_by_filetype('key') }
93
93
 
94
94
  it 'finds ExtractorKlass by matching file type' do
95
95
  should eql 'value'
@@ -133,9 +133,9 @@ module CommentExtractor
133
133
  before do
134
134
  allow(::CommentExtractor).to receive(:configuration).
135
135
  and_return(stub_configuration)
136
- allow(ExtractorManager).to receive(:find_extractor_by_shebang).
136
+ allow(Extractors).to receive(:find_by_shebang).
137
137
  and_return(nil)
138
- allow(ExtractorManager).to receive(:find_extractor_by_filename).
138
+ allow(Extractors).to receive(:find_by_filename).
139
139
  and_return(nil)
140
140
  end
141
141
 
@@ -169,7 +169,7 @@ module CommentExtractor
169
169
  subject { registered_extractors }
170
170
 
171
171
  let(:described_method) { described_class.send(:initialize_extractors!) }
172
- let(:default_extractors) { ExtractorManager.default_extractors }
172
+ let(:default_extractors) { Extractors.default_extractors }
173
173
 
174
174
  it 'initializes extractors' do
175
175
  expect(subject).to be_nil
@@ -2,10 +2,8 @@ require 'spec_helper'
2
2
  require 'comment_extractor/file'
3
3
  require 'tempfile'
4
4
 
5
- using CommentExtractor::DetectableSchemeFile
6
-
7
5
  module CommentExtractor
8
- describe DetectableSchemeFile do
6
+ describe File do
9
7
  let(:file) { File.new(file_path) }
10
8
  let(:asset_dir) { File.expand_path('../../assets', __FILE__) }
11
9
  let(:binary_path) { "#{asset_dir}/binary_file" }
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'comment_extractor/parser'
3
3
 
4
- using CommentExtractor::DetectableSchemeFile
5
-
6
4
  module CommentExtractor
7
5
  describe Parser do
8
6
  let(:expected_comments) { [] }
@@ -36,16 +34,17 @@ module CommentExtractor
36
34
  end
37
35
 
38
36
  describe 'ClassMethods' do
37
+ let(:file_path) { __FILE__ }
38
+
39
39
  describe '.for' do
40
40
  subject { described_class.for(file_path) }
41
- let(:file_path) { __FILE__ }
42
41
 
43
- context 'when extractor is found' do
44
- before do
45
- allow(ExtractorManager).to receive(:can_extract).
46
- and_return(stub_extractor)
47
- end
42
+ before do
43
+ allow(Extractors).to receive(:can_extract).
44
+ and_return(stub_extractor)
45
+ end
48
46
 
47
+ context 'when extractor is found' do
49
48
  it 'initializes extractor' do
50
49
  expect(subject).to be_an_instance_of described_class
51
50
  extractor = subject.extractor
@@ -55,6 +54,17 @@ module CommentExtractor
55
54
  end
56
55
  end
57
56
 
57
+ describe '.initialize_with_extractor' do
58
+ subject { described_class.initialize_with_extractor(file_path, stub_extractor) }
59
+
60
+ context 'when extractor is found' do
61
+ it 'initializes extractor' do
62
+ expect(subject).to be_an_instance_of described_class
63
+ expect(subject.extractor).to be_an_instance_of stub_extractor
64
+ end
65
+ end
66
+ end
67
+
58
68
  describe '.new' do
59
69
  subject { described_class.new(stub_extractor) }
60
70
 
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'comment_extractor/string_scanner'
3
+
4
+ module CommentExtractor
5
+ describe StringScanner do
6
+ let(:scanner) { StringScanner.new("...\n...") }
7
+
8
+ describe '#current_line' do
9
+ it 'returns current line number' do
10
+ expect(scanner.current_line).to eql 1
11
+
12
+ scanner.scan(/^.*$/) # Scanning one line
13
+ expect(scanner.current_line).to eql 1
14
+
15
+ scanner.scan(/\n/) # Go to next line
16
+ expect(scanner.current_line).to eql 2
17
+ end
18
+ end
19
+ end
20
+ end
@@ -13,7 +13,6 @@ require 'rspec/comment_extractor'
13
13
  RSpec.configure do |config|
14
14
  config.order = 'random'
15
15
  config.run_all_when_everything_filtered = true
16
- config.show_failures_in_pending_blocks = true
17
16
  config.raise_errors_for_deprecations!
18
17
  config.include RSpec::CommentExtractor::ExtractorExampleGroup, type: :extractor, example_group: {
19
18
  file_path: Regexp.compile(%w[spec comment_extractor extractor .*.rb].join('[\\\/]'))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comment_extractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - alpaca-tc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2014-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -25,13 +25,13 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rdoc
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -124,10 +124,10 @@ files:
124
124
  - lib/comment_extractor/extractor/tex.rb
125
125
  - lib/comment_extractor/extractor/text.rb
126
126
  - lib/comment_extractor/extractor/yaml.rb
127
- - lib/comment_extractor/extractor_manager.rb
127
+ - lib/comment_extractor/extractors.rb
128
128
  - lib/comment_extractor/file.rb
129
129
  - lib/comment_extractor/parser.rb
130
- - lib/comment_extractor/smart_string_scanner.rb
130
+ - lib/comment_extractor/string_scanner.rb
131
131
  - lib/comment_extractor/version.rb
132
132
  - spec/assets/binary_file
133
133
  - spec/assets/shebang_file
@@ -224,11 +224,11 @@ files:
224
224
  - spec/comment_extractor/extractor/tex_spec.rb
225
225
  - spec/comment_extractor/extractor/text_spec.rb
226
226
  - spec/comment_extractor/extractor/yaml_spec.rb
227
- - spec/comment_extractor/extractor_manager_spec.rb
228
227
  - spec/comment_extractor/extractor_spec.rb
228
+ - spec/comment_extractor/extractors_spec.rb
229
229
  - spec/comment_extractor/file_spec.rb
230
230
  - spec/comment_extractor/parser_spec.rb
231
- - spec/comment_extractor/smart_string_scanner_spec.rb
231
+ - spec/comment_extractor/string_scanner_spec.rb
232
232
  - spec/comment_extractor/version_spec.rb
233
233
  - spec/comment_extractor_spec.rb
234
234
  - spec/spec_helper.rb
@@ -356,11 +356,11 @@ test_files:
356
356
  - spec/comment_extractor/extractor/tex_spec.rb
357
357
  - spec/comment_extractor/extractor/text_spec.rb
358
358
  - spec/comment_extractor/extractor/yaml_spec.rb
359
- - spec/comment_extractor/extractor_manager_spec.rb
360
359
  - spec/comment_extractor/extractor_spec.rb
360
+ - spec/comment_extractor/extractors_spec.rb
361
361
  - spec/comment_extractor/file_spec.rb
362
362
  - spec/comment_extractor/parser_spec.rb
363
- - spec/comment_extractor/smart_string_scanner_spec.rb
363
+ - spec/comment_extractor/string_scanner_spec.rb
364
364
  - spec/comment_extractor/version_spec.rb
365
365
  - spec/comment_extractor_spec.rb
366
366
  - spec/spec_helper.rb
@@ -1,11 +0,0 @@
1
- require 'strscan'
2
-
3
- module CommentExtractor
4
- module SmartStringScanner
5
- refine StringScanner do
6
- def current_line
7
- string[0...charpos].count("\n") + 1
8
- end
9
- end
10
- end
11
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
- require 'comment_extractor/smart_string_scanner'
3
-
4
- using CommentExtractor::SmartStringScanner
5
-
6
- module CommentExtractor
7
- describe SmartStringScanner do
8
- let(:scanner) { StringScanner.new("...\n...") }
9
-
10
- describe 'refines #current_line' do
11
- context 'when scanner has already used' do
12
- it 'returns current line number' do
13
- expect(scanner.current_line).to eql 1
14
-
15
- scanner.scan(/^.*$/) # Scanning one line
16
- expect(scanner.current_line).to eql 1
17
-
18
- scanner.scan(/\n/) # Go to next line
19
- expect(scanner.current_line).to eql 2
20
- end
21
- end
22
- end
23
- end
24
- end