snail_parser 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4054492e293f575cab43d319bcf53f7a9fc81e5f
4
- data.tar.gz: b35c2d78d8827d311162c750955efa58ac648bb8
3
+ metadata.gz: b0ac283bb474f376a1777787bff35b8623a419ea
4
+ data.tar.gz: a71eca840272647c1c9d2dc62365866397baeaa0
5
5
  SHA512:
6
- metadata.gz: 7329b7cc2074d853c2ee4b6853fbd397c6d2e746b9d9bb50e400be8edcc1d2e578e74e04aed78a5fc0924e812d5c933a574bb82e940e4bb961dd4d2511d99a67
7
- data.tar.gz: b87effd908490e761e88eba39475eb124d83ce5e5ab6f12e59396ed8231abd669f33f6634a765d505a4f50405a7e2b403486e283fa79f8d3708a97b9f0bd09d3
6
+ metadata.gz: e840d5f7ae9885c25b84513036253fa86c9ea46e943d8845c9d679b62366de9f85ef76c36140ebe699bedb9514ad577934bbdbc7b868f61c9bb2d1199dd454fe
7
+ data.tar.gz: 2940a1652a413a43d53598b6ddcc788398ebe476a68a18fc7481a14622951db9d074bbbc9fb780bbac17e39692375ce07869cdf7522910e4d2325c763e5b7fff
data/bin/snail_parser CHANGED
@@ -3,4 +3,4 @@
3
3
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
4
4
  require 'snail_parser'
5
5
 
6
- SnailParser.invoke!
6
+ print SnailParser.invoke!
@@ -0,0 +1,5 @@
1
+ class SnailParser::Formatter::Default < SnailParser::Formatter
2
+ def report
3
+ @result
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'json'
2
+
3
+ class SnailParser::Formatter::Json < SnailParser::Formatter
4
+ def report
5
+ @result.to_json
6
+ end
7
+ end
@@ -1,6 +1,7 @@
1
1
  module SnailParser
2
- class Reporter
3
- autoload :Json, 'snail_parser/reporter/json'
2
+ class Formatter
3
+ autoload :Json, 'snail_parser/formatter/json'
4
+ autoload :Default, 'snail_parser/formatter/default'
4
5
 
5
6
  def initialize(result)
6
7
  @result = result
@@ -19,9 +19,9 @@ module SnailParser
19
19
  SnailParser.configuration[:path] = path
20
20
  end
21
21
 
22
- parser.on('--reporter REPORTER') do |klass|
23
- # SnailParser.configuration[:reporter] = Reporter.const_get(klass)
24
- SnailParser.configuration[:reporter] = Reporter::Json
22
+ parser.on('--formatter FORMATTER') do |klass|
23
+ # SnailParser.configuration[:formatter] = Formatter.const_get(klass)
24
+ SnailParser.configuration[:formatter] = Formatter::Json
25
25
  end
26
26
 
27
27
  parser.on_tail('-h', '--help', 'Show this usage message and quit.') do |setting|
@@ -1,3 +1,3 @@
1
1
  module SnailParser
2
- Version = '0.0.1'
2
+ Version = '0.0.2'
3
3
  end
data/lib/snail_parser.rb CHANGED
@@ -1,13 +1,21 @@
1
1
  require 'snail_parser/option_parser'
2
2
  require 'snail_parser/parser'
3
- require 'snail_parser/reporter'
3
+ require 'snail_parser/formatter'
4
4
  require 'snail_parser/version'
5
5
 
6
6
  module SnailParser
7
7
  def self.invoke!
8
8
  OptionParser.new(ARGV).parse!
9
+ run
10
+ end
11
+
12
+ def self.run
9
13
  result = Parser.parse(configuration[:path])
10
- configuration[:reporter].new(result).report
14
+ configuration[:formatter].new(result).report
15
+ end
16
+
17
+ def self.configure
18
+ yield(configuration)
11
19
  end
12
20
 
13
21
  def self.configuration
@@ -18,7 +26,7 @@ module SnailParser
18
26
 
19
27
  def self.default_configuration
20
28
  {
21
- reporter: Reporter::Json
29
+ formatter: Formatter::Default
22
30
  }
23
31
  end
24
32
  end
@@ -1,5 +1,5 @@
1
- RSpec.describe SnailParser::Reporter::Json do
2
- let(:reporter) { described_class.new(result) }
1
+ RSpec.describe SnailParser::Formatter::Json do
2
+ let(:formatter) { described_class.new(result) }
3
3
  let(:result) do
4
4
  [
5
5
  {
@@ -13,8 +13,9 @@ RSpec.describe SnailParser::Reporter::Json do
13
13
  end
14
14
 
15
15
  describe '#report' do
16
+ subject { formatter.report }
16
17
  it 'report as json' do
17
- expect { reporter.report }.to output(result.to_json).to_stdout
18
+ is_expected.to eq result.to_json
18
19
  end
19
20
  end
20
21
  end
@@ -18,8 +18,8 @@ RSpec.describe SnailParser::OptionParser do
18
18
  end
19
19
  end
20
20
 
21
- it_should_behave_like 'parsing option', :reporter, SnailParser::Reporter::Json do
22
- let(:argv) { %w(--reporter Json) }
21
+ it_should_behave_like 'parsing option', :formatter, SnailParser::Formatter::Json do
22
+ let(:argv) { %w(--formatter Json) }
23
23
  end
24
24
 
25
25
  it_should_behave_like 'parsing option', :path, 'path' do
@@ -1,8 +1,25 @@
1
1
  RSpec.describe SnailParser do
2
+ before do
3
+ SnailParser.instance_variable_set(:@configuration, nil)
4
+ end
5
+
2
6
  describe '.configuration' do
3
7
  subject { described_class.configuration }
4
- it 'sets default configuration' do
5
- is_expected.to eq(reporter: SnailParser::Reporter::Json)
8
+ it 'returns configuration' do
9
+ is_expected.to eq(formatter: SnailParser::Formatter::Default)
10
+ end
11
+ end
12
+
13
+ describe '.configure' do
14
+ before do
15
+ described_class.configure do |config|
16
+ config[:path] = path
17
+ end
18
+ end
19
+ let(:path) { 'path' }
20
+
21
+ it 'set path to configuration' do
22
+ expect(described_class.configuration[:path]).to eq(path)
6
23
  end
7
24
  end
8
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snail_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - alpaca-tc
@@ -63,15 +63,16 @@ files:
63
63
  - README.md
64
64
  - bin/snail_parser
65
65
  - lib/snail_parser.rb
66
+ - lib/snail_parser/formatter.rb
67
+ - lib/snail_parser/formatter/default.rb
68
+ - lib/snail_parser/formatter/json.rb
66
69
  - lib/snail_parser/option_parser.rb
67
70
  - lib/snail_parser/parser.rb
68
- - lib/snail_parser/reporter.rb
69
- - lib/snail_parser/reporter/json.rb
70
71
  - lib/snail_parser/version.rb
71
72
  - spec/fixtures/test.csv
73
+ - spec/lib/snail_parser/formatter/json_spec.rb
72
74
  - spec/lib/snail_parser/option_parser_spec.rb
73
75
  - spec/lib/snail_parser/parser_spec.rb
74
- - spec/lib/snail_parser/reporter/json_spec.rb
75
76
  - spec/lib/snail_parser/version_spec.rb
76
77
  - spec/lib/snail_parser_spec.rb
77
78
  - spec/spec_helper.rb
@@ -101,9 +102,9 @@ specification_version: 4
101
102
  summary: ''
102
103
  test_files:
103
104
  - spec/fixtures/test.csv
105
+ - spec/lib/snail_parser/formatter/json_spec.rb
104
106
  - spec/lib/snail_parser/option_parser_spec.rb
105
107
  - spec/lib/snail_parser/parser_spec.rb
106
- - spec/lib/snail_parser/reporter/json_spec.rb
107
108
  - spec/lib/snail_parser/version_spec.rb
108
109
  - spec/lib/snail_parser_spec.rb
109
110
  - spec/spec_helper.rb
@@ -1,7 +0,0 @@
1
- require 'json'
2
-
3
- class SnailParser::Reporter::Json < SnailParser::Reporter
4
- def report
5
- print @result.to_json
6
- end
7
- end