snail_parser 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/snail_parser/formatter.rb +1 -0
- data/lib/snail_parser/formatter/vim.rb +22 -0
- data/lib/snail_parser/option_parser.rb +1 -2
- data/lib/snail_parser/version.rb +1 -1
- data/spec/lib/snail_parser/formatter/json_spec.rb +0 -13
- data/spec/lib/snail_parser/formatter/vim_spec.rb +10 -0
- data/spec/lib/snail_parser/option_parser_spec.rb +2 -2
- data/spec/support/formatter_support.rb +22 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dde26dcd7525f6c28134a6e2f246ae58337d5df2
|
4
|
+
data.tar.gz: 69d3bd6c1c10d4b86c6a1fc9bf08d140fa376978
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7848aea8a83a11b63109d53ac326e04cacfdcb9fe0ce1955d2c0e3d573fc0a28747299ab2ddbe8ef6ac758df15e23d54a751afa5060896a693962a55eb72cf2f
|
7
|
+
data.tar.gz: 0c7d25f628097cab22bfaeb7b28534b9d367ddcff9caecdd74e584743035c411e7da77e5e5c4ffe49c13f03cc5dda09ae5b6cb9340d7b9c6118fed03fe5f863b
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class SnailParser::Formatter::Vim < SnailParser::Formatter
|
2
|
+
def report
|
3
|
+
rows = @result.each_with_object([]) do |row, result|
|
4
|
+
line = row.map { |key, value| "'#{key}':#{cast_value_to_vim_object(value)}" }
|
5
|
+
result << "{#{line.join(',')}}"
|
6
|
+
end
|
7
|
+
|
8
|
+
"[#{rows.join(',')}]"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def cast_value_to_vim_object(value)
|
14
|
+
value = case value
|
15
|
+
when Time
|
16
|
+
sprintf('%02d:%02d:%02d', value.hour, value.min, value.sec)
|
17
|
+
when Date, String, Integer, NilClass
|
18
|
+
value
|
19
|
+
end
|
20
|
+
"'#{value}'"
|
21
|
+
end
|
22
|
+
end
|
@@ -20,8 +20,7 @@ module SnailParser
|
|
20
20
|
end
|
21
21
|
|
22
22
|
parser.on('--formatter FORMATTER') do |klass|
|
23
|
-
|
24
|
-
SnailParser.configuration[:formatter] = Formatter::Json
|
23
|
+
SnailParser.configuration[:formatter] = Formatter.const_get(klass)
|
25
24
|
end
|
26
25
|
|
27
26
|
parser.on_tail('-h', '--help', 'Show this usage message and quit.') do |setting|
|
data/lib/snail_parser/version.rb
CHANGED
@@ -1,17 +1,4 @@
|
|
1
1
|
RSpec.describe SnailParser::Formatter::Json do
|
2
|
-
let(:formatter) { described_class.new(result) }
|
3
|
-
let(:result) do
|
4
|
-
[
|
5
|
-
{
|
6
|
-
title: 'do_something2',
|
7
|
-
status: 'Overdue',
|
8
|
-
beginning_at: Date.new,
|
9
|
-
completed_at: nil,
|
10
|
-
time_spent: Time.new
|
11
|
-
}
|
12
|
-
]
|
13
|
-
end
|
14
|
-
|
15
2
|
describe '#report' do
|
16
3
|
subject { formatter.report }
|
17
4
|
it 'report as json' do
|
@@ -0,0 +1,10 @@
|
|
1
|
+
RSpec.describe SnailParser::Formatter::Vim do
|
2
|
+
describe '#report' do
|
3
|
+
subject { formatter.report }
|
4
|
+
let(:expected){"[{'title':'do_something2','status':'Overdue','beginning_at':'2014-09-26','completed_at':'','time_spent':'01:02:03'}]"}
|
5
|
+
|
6
|
+
it 'report for vim' do
|
7
|
+
is_expected.to eq expected
|
8
|
+
end
|
9
|
+
end
|
10
|
+
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', :formatter, SnailParser::Formatter::
|
22
|
-
let(:argv) { %w(--formatter
|
21
|
+
it_should_behave_like 'parsing option', :formatter, SnailParser::Formatter::Vim do
|
22
|
+
let(:argv) { %w(--formatter Vim) }
|
23
23
|
end
|
24
24
|
|
25
25
|
it_should_behave_like 'parsing option', :path, 'path' do
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module FormatterSupport
|
2
|
+
def self.included(klass)
|
3
|
+
klass.class_eval do
|
4
|
+
let(:formatter) { described_class.new(result) }
|
5
|
+
let(:result) do
|
6
|
+
[
|
7
|
+
{
|
8
|
+
title: 'do_something2',
|
9
|
+
status: 'Overdue',
|
10
|
+
beginning_at: Date.parse('2014-09-26'),
|
11
|
+
completed_at: nil,
|
12
|
+
time_spent: Time.parse('01:02:03')
|
13
|
+
}
|
14
|
+
]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.include self, file_path: /lib\/snail_parser\/formatter/
|
21
|
+
end
|
22
|
+
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.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alpaca-tc
|
@@ -66,16 +66,19 @@ files:
|
|
66
66
|
- lib/snail_parser/formatter.rb
|
67
67
|
- lib/snail_parser/formatter/default.rb
|
68
68
|
- lib/snail_parser/formatter/json.rb
|
69
|
+
- lib/snail_parser/formatter/vim.rb
|
69
70
|
- lib/snail_parser/option_parser.rb
|
70
71
|
- lib/snail_parser/parser.rb
|
71
72
|
- lib/snail_parser/version.rb
|
72
73
|
- spec/fixtures/test.csv
|
73
74
|
- spec/lib/snail_parser/formatter/json_spec.rb
|
75
|
+
- spec/lib/snail_parser/formatter/vim_spec.rb
|
74
76
|
- spec/lib/snail_parser/option_parser_spec.rb
|
75
77
|
- spec/lib/snail_parser/parser_spec.rb
|
76
78
|
- spec/lib/snail_parser/version_spec.rb
|
77
79
|
- spec/lib/snail_parser_spec.rb
|
78
80
|
- spec/spec_helper.rb
|
81
|
+
- spec/support/formatter_support.rb
|
79
82
|
homepage: https://github.com/alpaca-tc/snail_parser
|
80
83
|
licenses:
|
81
84
|
- MIT
|
@@ -103,8 +106,10 @@ summary: ''
|
|
103
106
|
test_files:
|
104
107
|
- spec/fixtures/test.csv
|
105
108
|
- spec/lib/snail_parser/formatter/json_spec.rb
|
109
|
+
- spec/lib/snail_parser/formatter/vim_spec.rb
|
106
110
|
- spec/lib/snail_parser/option_parser_spec.rb
|
107
111
|
- spec/lib/snail_parser/parser_spec.rb
|
108
112
|
- spec/lib/snail_parser/version_spec.rb
|
109
113
|
- spec/lib/snail_parser_spec.rb
|
110
114
|
- spec/spec_helper.rb
|
115
|
+
- spec/support/formatter_support.rb
|