snail_parser 0.0.1
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +15 -0
- data/bin/snail_parser +6 -0
- data/lib/snail_parser/option_parser.rb +39 -0
- data/lib/snail_parser/parser.rb +53 -0
- data/lib/snail_parser/reporter/json.rb +7 -0
- data/lib/snail_parser/reporter.rb +13 -0
- data/lib/snail_parser/version.rb +3 -0
- data/lib/snail_parser.rb +24 -0
- data/spec/fixtures/test.csv +15 -0
- data/spec/lib/snail_parser/option_parser_spec.rb +29 -0
- data/spec/lib/snail_parser/parser_spec.rb +31 -0
- data/spec/lib/snail_parser/reporter/json_spec.rb +20 -0
- data/spec/lib/snail_parser/version_spec.rb +6 -0
- data/spec/lib/snail_parser_spec.rb +8 -0
- data/spec/spec_helper.rb +25 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4054492e293f575cab43d319bcf53f7a9fc81e5f
|
4
|
+
data.tar.gz: b35c2d78d8827d311162c750955efa58ac648bb8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7329b7cc2074d853c2ee4b6853fbd397c6d2e746b9d9bb50e400be8edcc1d2e578e74e04aed78a5fc0924e812d5c933a574bb82e940e4bb961dd4d2511d99a67
|
7
|
+
data.tar.gz: b87effd908490e761e88eba39475eb124d83ce5e5ab6f12e59396ed8231abd669f33f6634a765d505a4f50405a7e2b403486e283fa79f8d3708a97b9f0bd09d3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) <2014> <Ishii Hiroyuki>
|
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,15 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
Parser for [snail](https://itunes.apple.com/us/app/snail-time-and-task-manager/id582414050?mt=12)
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
```
|
8
|
+
gem install snail_parser
|
9
|
+
```
|
10
|
+
|
11
|
+
## How to use
|
12
|
+
|
13
|
+
```
|
14
|
+
snail_parser --path path/to/SnailOutput.csv --reporter Json
|
15
|
+
```
|
data/bin/snail_parser
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module SnailParser
|
4
|
+
class OptionParser
|
5
|
+
def initialize(argv)
|
6
|
+
@original_argv = argv.dup
|
7
|
+
@argv = argv
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse!
|
11
|
+
option_parser.parse!(@argv)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def option_parser
|
17
|
+
@option_parser ||= ::OptionParser.new do |parser|
|
18
|
+
parser.on('--path PATH') do |path|
|
19
|
+
SnailParser.configuration[:path] = path
|
20
|
+
end
|
21
|
+
|
22
|
+
parser.on('--reporter REPORTER') do |klass|
|
23
|
+
# SnailParser.configuration[:reporter] = Reporter.const_get(klass)
|
24
|
+
SnailParser.configuration[:reporter] = Reporter::Json
|
25
|
+
end
|
26
|
+
|
27
|
+
parser.on_tail('-h', '--help', 'Show this usage message and quit.') do |setting|
|
28
|
+
puts parser.help
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
parser.on_tail('-v', '--version', 'Show version information about tamago and quit.') do
|
33
|
+
puts SnailParser::Version
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module SnailParser
|
5
|
+
class Parser < CSV
|
6
|
+
Column = {
|
7
|
+
title: :string,
|
8
|
+
status: :string,
|
9
|
+
beginning_at: :date,
|
10
|
+
completed_at: :date,
|
11
|
+
time_spent: :time
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
def self.parse(path)
|
15
|
+
new(path).rows
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(path)
|
19
|
+
CSV.open(path, 'r') do |f|
|
20
|
+
f.shift # Remove header
|
21
|
+
f.each { |row| rows << parse_row(row) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def rows
|
26
|
+
@rows ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def parse_row(row)
|
32
|
+
Column.each_with_object({}).with_index do |((key, type), result), index|
|
33
|
+
result[key] = cast_type(row[index], type)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def cast_type(value, type)
|
38
|
+
return if value.nil?
|
39
|
+
|
40
|
+
case type
|
41
|
+
when :string
|
42
|
+
value.to_s
|
43
|
+
when :date
|
44
|
+
Date.parse(value)
|
45
|
+
when :time
|
46
|
+
time_spent = Time.parse(value)
|
47
|
+
Time.mktime(1, 1, 1, time_spent.hour, time_spent.min, time_spent.sec)
|
48
|
+
else
|
49
|
+
value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/snail_parser.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'snail_parser/option_parser'
|
2
|
+
require 'snail_parser/parser'
|
3
|
+
require 'snail_parser/reporter'
|
4
|
+
require 'snail_parser/version'
|
5
|
+
|
6
|
+
module SnailParser
|
7
|
+
def self.invoke!
|
8
|
+
OptionParser.new(ARGV).parse!
|
9
|
+
result = Parser.parse(configuration[:path])
|
10
|
+
configuration[:reporter].new(result).report
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.configuration
|
14
|
+
@configuration ||= default_configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def self.default_configuration
|
20
|
+
{
|
21
|
+
reporter: Reporter::Json
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Title,Status,Start Date,Completion Date,Time Spent
|
2
|
+
"do_something1",Overdue,2014-09-11,,01:46:53
|
3
|
+
"do_something2",Overdue,2014-09-25,,00:39:45
|
4
|
+
"do_something3",Overdue,2014-09-25,,01:13:22
|
5
|
+
"do_something4",New,2014-09-26,,00:35:03
|
6
|
+
"do_something5",Completed,2014-09-26,2014-09-26,00:08:59
|
7
|
+
"do_something6",Completed,2014-09-26,2014-09-26,01:44:00
|
8
|
+
"do_something7",Overdue,2014-07-14,,00:07:25
|
9
|
+
"do_something8",Overdue,2014-09-11,,00:00:01
|
10
|
+
"do_something9",Overdue,2014-09-25,,00:40:43
|
11
|
+
"do_something10",New,2014-09-26,,01:48:34
|
12
|
+
"do_something11",Completed,2014-09-26,2014-09-26,01:11:12
|
13
|
+
"do_something12",New,2014-09-26,,00:40:11
|
14
|
+
"do_something13",Completed,2014-09-26,2014-09-26,00:29:25
|
15
|
+
"do_something14",Completed,2014-09-26,2014-09-26,00:00:10
|
@@ -0,0 +1,29 @@
|
|
1
|
+
RSpec.describe SnailParser::OptionParser do
|
2
|
+
let(:option_parser) { described_class.new(argv) }
|
3
|
+
|
4
|
+
describe '#parse!' do
|
5
|
+
before do
|
6
|
+
option_parser.parse!
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:configuration) { }
|
10
|
+
|
11
|
+
shared_examples_for 'parsing option' do |key, value|
|
12
|
+
subject { SnailParser.configuration[key] }
|
13
|
+
|
14
|
+
context "given --#{key} option" do
|
15
|
+
it "set #{key} to #{value}" do
|
16
|
+
is_expected.to eql(value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like 'parsing option', :reporter, SnailParser::Reporter::Json do
|
22
|
+
let(:argv) { %w(--reporter Json) }
|
23
|
+
end
|
24
|
+
|
25
|
+
it_should_behave_like 'parsing option', :path, 'path' do
|
26
|
+
let(:argv) { %w(--path path) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
RSpec.describe SnailParser::Parser do
|
2
|
+
let(:csv) { spec_root.join('fixtures/test.csv') }
|
3
|
+
|
4
|
+
describe 'ClassMethods' do
|
5
|
+
describe '.parse' do
|
6
|
+
subject { described_class.parse(csv) }
|
7
|
+
|
8
|
+
it 'parse CSV' do
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'InstanceMethods' do
|
14
|
+
let(:parser) { described_class.new(csv) }
|
15
|
+
|
16
|
+
describe '#rows' do
|
17
|
+
subject { parser.rows }
|
18
|
+
|
19
|
+
it 'returns parsed CSV' do
|
20
|
+
expect(subject.length).to eq 14
|
21
|
+
|
22
|
+
first = subject.first
|
23
|
+
expect(first[:title]).to eq 'do_something1'
|
24
|
+
expect(first[:status]).to eq 'Overdue'
|
25
|
+
expect(first[:beginning_at]).to be_a(Date)
|
26
|
+
expect(first[:completed_at]).to be_nil
|
27
|
+
expect(first[:time_spent]).to be_a(Time)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
RSpec.describe SnailParser::Reporter::Json do
|
2
|
+
let(:reporter) { 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
|
+
describe '#report' do
|
16
|
+
it 'report as json' do
|
17
|
+
expect { reporter.report }.to output(result.to_json).to_stdout
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
11
|
+
require 'snail_parser'
|
12
|
+
|
13
|
+
Dir[File.expand_path('../support', __FILE__) + '/**/*.rb'].each do |f|
|
14
|
+
require f
|
15
|
+
end
|
16
|
+
|
17
|
+
def spec_root
|
18
|
+
Pathname.new(__dir__)
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.order = 'random'
|
23
|
+
config.run_all_when_everything_filtered = true
|
24
|
+
config.raise_errors_for_deprecations!
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: snail_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- alpaca-tc
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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: ''
|
56
|
+
email: alpaca-tc@alpaca.tc
|
57
|
+
executables:
|
58
|
+
- snail_parser
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- bin/snail_parser
|
65
|
+
- lib/snail_parser.rb
|
66
|
+
- lib/snail_parser/option_parser.rb
|
67
|
+
- lib/snail_parser/parser.rb
|
68
|
+
- lib/snail_parser/reporter.rb
|
69
|
+
- lib/snail_parser/reporter/json.rb
|
70
|
+
- lib/snail_parser/version.rb
|
71
|
+
- spec/fixtures/test.csv
|
72
|
+
- spec/lib/snail_parser/option_parser_spec.rb
|
73
|
+
- spec/lib/snail_parser/parser_spec.rb
|
74
|
+
- spec/lib/snail_parser/reporter/json_spec.rb
|
75
|
+
- spec/lib/snail_parser/version_spec.rb
|
76
|
+
- spec/lib/snail_parser_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: https://github.com/alpaca-tc/snail_parser
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.0.0
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.3.0
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: ''
|
102
|
+
test_files:
|
103
|
+
- spec/fixtures/test.csv
|
104
|
+
- spec/lib/snail_parser/option_parser_spec.rb
|
105
|
+
- spec/lib/snail_parser/parser_spec.rb
|
106
|
+
- spec/lib/snail_parser/reporter/json_spec.rb
|
107
|
+
- spec/lib/snail_parser/version_spec.rb
|
108
|
+
- spec/lib/snail_parser_spec.rb
|
109
|
+
- spec/spec_helper.rb
|