balboa 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/bin/balboa +8 -4
- data/lib/balboa/cli/command/punch_command.rb +4 -47
- data/lib/balboa/cli/defaults.rb +5 -6
- data/lib/balboa/punch_date.rb +49 -0
- data/lib/balboa/version.rb +1 -1
- data/lib/balboa.rb +0 -2
- data/spec/balboa/cli/defaults_spec.rb +7 -0
- data/spec/balboa/interactor/interactor_wrapper_spec.rb +9 -0
- data/spec/balboa/punch_date_spec.rb +65 -0
- data/spec/balboa_spec.rb +4 -0
- metadata +4 -3
- data/lib/balboa/cli/command/help_command.rb +0 -24
- data/lib/balboa/cli/options.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5afd6ed3afeeb7f8b8df77c2eac12c2f0c331056
|
4
|
+
data.tar.gz: f61c6b46fe1b9cfdf11ad6517c7576d672fae7d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c42fb6f86aefaf243229ce60e8192c24f4970ed2892754fef303f775a268f9a56dec8ecb49061b37ea561f079c2c74bc7fb14fc446a1a226ab0e75dbd03c8159
|
7
|
+
data.tar.gz: 392b518101ad26e4be02afd360eace9dc9980f8e546609df9d9ca7bb1b59c9f2b7b6acb14df75b5df12159331b4b1ade2e4619e1a8128cf9a27143d091367594
|
data/.gitignore
CHANGED
data/bin/balboa
CHANGED
@@ -2,20 +2,24 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require_relative '../lib/balboa'
|
5
|
+
require_relative '../lib/balboa/cli/parser_builder'
|
6
|
+
require_relative '../lib/balboa/interactor/interactor_builder'
|
5
7
|
|
6
|
-
|
8
|
+
require 'highline/import'
|
9
|
+
|
10
|
+
options = if File.exist?(Balboa::CONFIG_FILE)
|
7
11
|
YAML.load_file(Balboa::CONFIG_FILE)
|
8
12
|
else
|
9
|
-
Balboa::CLI::Defaults.prompt
|
13
|
+
Balboa::CLI::Defaults.prompt(HighLine)
|
10
14
|
end
|
11
15
|
|
12
|
-
|
16
|
+
Balboa::CLI::ParserBuilder.create(ARGV, options).parse!
|
13
17
|
|
14
18
|
raw_interactor = Balboa::Interactor::InteractorBuilder.create(options)
|
15
19
|
interactor = Balboa::Interactor::InteractorWrapper.new(raw_interactor)
|
16
20
|
|
17
21
|
app_last = Balboa::CLI::Command::LastCommand.new(interactor)
|
18
|
-
app_punch = Balboa::CLI::Command::PunchCommand.new(interactor)
|
22
|
+
app_punch = Balboa::CLI::Command::PunchCommand.new(interactor, HighLine)
|
19
23
|
app_reset = Balboa::CLI::Command::ResetCommand.new
|
20
24
|
app_star_wars = Balboa::CLI::Command::StarWarsCommand.new
|
21
25
|
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require 'highline/import'
|
3
|
+
require_relative '../../punch_date'
|
5
4
|
|
6
5
|
module Balboa
|
7
6
|
module CLI
|
8
7
|
module Command
|
9
8
|
class PunchCommand
|
10
|
-
def initialize(interactor)
|
9
|
+
def initialize(interactor, cli)
|
11
10
|
@interactor = interactor
|
11
|
+
@cli = cli
|
12
12
|
end
|
13
13
|
|
14
14
|
def execute
|
@@ -25,7 +25,7 @@ module Balboa
|
|
25
25
|
yesterday = Date.today - 1
|
26
26
|
|
27
27
|
(last_punch_date..yesterday).map do |date|
|
28
|
-
PunchDate.new(date)
|
28
|
+
PunchDate.new(date, @cli)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -40,49 +40,6 @@ module Balboa
|
|
40
40
|
def last_punch_date
|
41
41
|
Date.parse(@interactor.last) + 1
|
42
42
|
end
|
43
|
-
|
44
|
-
class PunchDate
|
45
|
-
def initialize(date)
|
46
|
-
@date = date
|
47
|
-
@holiday = Hash(Holidays.on(@date, :br).first)
|
48
|
-
end
|
49
|
-
|
50
|
-
def punchable?
|
51
|
-
if weekend?
|
52
|
-
false
|
53
|
-
elsif holiday?
|
54
|
-
ask_for_punch
|
55
|
-
else
|
56
|
-
true
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def to_s
|
61
|
-
@date.to_s
|
62
|
-
end
|
63
|
-
|
64
|
-
def strftime(format)
|
65
|
-
@date.strftime(format)
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def ask_for_punch
|
71
|
-
HighLine.agree(" #{holiday_name}. Punch? (y|n) ")
|
72
|
-
end
|
73
|
-
|
74
|
-
def holiday_name
|
75
|
-
@holiday[:name]
|
76
|
-
end
|
77
|
-
|
78
|
-
def holiday?
|
79
|
-
!!@holiday
|
80
|
-
end
|
81
|
-
|
82
|
-
def weekend?
|
83
|
-
@date.sunday? || @date.saturday?
|
84
|
-
end
|
85
|
-
end
|
86
43
|
end
|
87
44
|
end
|
88
45
|
end
|
data/lib/balboa/cli/defaults.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
-
require 'highline'
|
5
4
|
|
6
5
|
module Balboa
|
7
6
|
module CLI
|
8
7
|
class Defaults
|
9
|
-
def self.prompt
|
10
|
-
new.prompt
|
8
|
+
def self.prompt(*args)
|
9
|
+
new(*args).prompt
|
11
10
|
end
|
12
11
|
|
13
|
-
def initialize
|
14
|
-
@config =
|
15
|
-
@cli =
|
12
|
+
def initialize(cli, config={})
|
13
|
+
@config = config
|
14
|
+
@cli = cli
|
16
15
|
end
|
17
16
|
|
18
17
|
def prompt
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'holidays'
|
4
|
+
|
5
|
+
module Balboa
|
6
|
+
class PunchDate
|
7
|
+
def initialize(date, cli)
|
8
|
+
@date = date
|
9
|
+
@cli = cli
|
10
|
+
@holiday = Hash(Holidays.on(date, :br).first)
|
11
|
+
end
|
12
|
+
|
13
|
+
def punchable?
|
14
|
+
if weekend?
|
15
|
+
false
|
16
|
+
elsif holiday?
|
17
|
+
ask_for_punch
|
18
|
+
else
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
@date.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def strftime(format)
|
28
|
+
@date.strftime(format)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def ask_for_punch
|
34
|
+
@cli.agree(" #{holiday_name}. Punch? (y|n) ")
|
35
|
+
end
|
36
|
+
|
37
|
+
def holiday_name
|
38
|
+
@holiday[:name]
|
39
|
+
end
|
40
|
+
|
41
|
+
def holiday?
|
42
|
+
!@holiday.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
def weekend?
|
46
|
+
@date.sunday? || @date.saturday?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/balboa/version.rb
CHANGED
data/lib/balboa.rb
CHANGED
@@ -6,13 +6,11 @@ require_relative 'balboa/host'
|
|
6
6
|
|
7
7
|
require_relative 'balboa/interactor/capybara_interactor'
|
8
8
|
require_relative 'balboa/interactor/interactor_wrapper'
|
9
|
-
require_relative 'balboa/interactor/interactor_builder'
|
10
9
|
require_relative 'balboa/interactor/command/fetch_last_punch_command'
|
11
10
|
require_relative 'balboa/interactor/command/fill_punch_command'
|
12
11
|
require_relative 'balboa/interactor/command/login_command'
|
13
12
|
|
14
13
|
require_relative 'balboa/cli/application'
|
15
|
-
require_relative 'balboa/cli/options'
|
16
14
|
require_relative 'balboa/cli/defaults'
|
17
15
|
require_relative 'balboa/cli/command/last_command'
|
18
16
|
require_relative 'balboa/cli/command/punch_command'
|
@@ -22,4 +22,13 @@ describe Balboa::Interactor::InteractorWrapper do
|
|
22
22
|
|
23
23
|
expect(interactor).to have_received(:last).once
|
24
24
|
end
|
25
|
+
|
26
|
+
it 'forwards options call to its dependency' do
|
27
|
+
interactor = double
|
28
|
+
allow(interactor).to receive(:options)
|
29
|
+
|
30
|
+
described_class.new(interactor).options
|
31
|
+
|
32
|
+
expect(interactor).to have_received(:options).once
|
33
|
+
end
|
25
34
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'highline/import'
|
5
|
+
|
6
|
+
describe Balboa::PunchDate do
|
7
|
+
it 'responds to to_s' do
|
8
|
+
date = Date.new(2011,1,1)
|
9
|
+
punch_date = described_class.new(date, nil)
|
10
|
+
|
11
|
+
expect(punch_date.to_s).to eq('2011-01-01')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'responds to strftime' do
|
15
|
+
date = Date.new(2011,1,1)
|
16
|
+
punch_date = described_class.new(date, nil)
|
17
|
+
|
18
|
+
expect(punch_date.strftime('%d/%m/%Y')).to eq('01/01/2011')
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'punchable' do
|
22
|
+
it 'returns false on satudays' do
|
23
|
+
date = Date.new(2011,1,1)
|
24
|
+
punch_date = described_class.new(date, nil)
|
25
|
+
|
26
|
+
expect(punch_date.punchable?).to be false
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns false on sundays' do
|
30
|
+
date = Date.new(2011,1,2)
|
31
|
+
punch_date = described_class.new(date, nil)
|
32
|
+
|
33
|
+
expect(punch_date.punchable?).to be false
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns true on a week day that is not a holiday' do
|
37
|
+
date = Date.new(2011,1,3)
|
38
|
+
punch_date = described_class.new(date, nil)
|
39
|
+
|
40
|
+
expect(punch_date.punchable?).to be true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns true if user says yes on holidays' do
|
44
|
+
input = StringIO.new("no\n")
|
45
|
+
output = StringIO.new
|
46
|
+
cli = HighLine.new(input, output)
|
47
|
+
|
48
|
+
date = Date.new(2011,4,21)
|
49
|
+
punch_date = described_class.new(date, cli)
|
50
|
+
|
51
|
+
expect(punch_date.punchable?).to be false
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns false if user says no on holidays' do
|
55
|
+
input = StringIO.new("yes\n")
|
56
|
+
output = StringIO.new
|
57
|
+
cli = HighLine.new(input, output)
|
58
|
+
|
59
|
+
date = Date.new(2011,4,21)
|
60
|
+
punch_date = described_class.new(date, cli)
|
61
|
+
|
62
|
+
expect(punch_date.punchable?).to be true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/balboa_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: balboa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Waldyr de Souza
|
@@ -91,13 +91,11 @@ files:
|
|
91
91
|
- features/support/env.rb
|
92
92
|
- lib/balboa.rb
|
93
93
|
- lib/balboa/cli/application.rb
|
94
|
-
- lib/balboa/cli/command/help_command.rb
|
95
94
|
- lib/balboa/cli/command/last_command.rb
|
96
95
|
- lib/balboa/cli/command/punch_command.rb
|
97
96
|
- lib/balboa/cli/command/reset_command.rb
|
98
97
|
- lib/balboa/cli/command/star_wars_command.rb
|
99
98
|
- lib/balboa/cli/defaults.rb
|
100
|
-
- lib/balboa/cli/options.rb
|
101
99
|
- lib/balboa/cli/parser_builder.rb
|
102
100
|
- lib/balboa/config_file.rb
|
103
101
|
- lib/balboa/host.rb
|
@@ -107,10 +105,13 @@ files:
|
|
107
105
|
- lib/balboa/interactor/command/login_command.rb
|
108
106
|
- lib/balboa/interactor/interactor_builder.rb
|
109
107
|
- lib/balboa/interactor/interactor_wrapper.rb
|
108
|
+
- lib/balboa/punch_date.rb
|
110
109
|
- lib/balboa/version.rb
|
111
110
|
- spec/balboa/capybara_interactor_spec.rb
|
112
111
|
- spec/balboa/cli/application_spec.rb
|
112
|
+
- spec/balboa/cli/defaults_spec.rb
|
113
113
|
- spec/balboa/interactor/interactor_wrapper_spec.rb
|
114
|
+
- spec/balboa/punch_date_spec.rb
|
114
115
|
- spec/balboa_spec.rb
|
115
116
|
- spec/spec_helper.rb
|
116
117
|
homepage:
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../version'
|
4
|
-
|
5
|
-
module Balboa
|
6
|
-
module CLI
|
7
|
-
module Command
|
8
|
-
class HelpCommand
|
9
|
-
def execute
|
10
|
-
$stdout.puts help
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def help
|
16
|
-
end
|
17
|
-
|
18
|
-
def quote
|
19
|
-
"`Life's not about how hard of a hit you can give...'"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/balboa/cli/options.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'parser_builder'
|
4
|
-
|
5
|
-
module Balboa
|
6
|
-
module CLI
|
7
|
-
class Options
|
8
|
-
def self.parse(*args)
|
9
|
-
new(*args).parse
|
10
|
-
rescue OptionParser::InvalidOption => error
|
11
|
-
$stderr.puts "Error: #{error}"
|
12
|
-
exit
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(argv=[], config={})
|
16
|
-
@config = config
|
17
|
-
@parser = Balboa::CLI::ParserBuilder.create(argv, config)
|
18
|
-
end
|
19
|
-
|
20
|
-
def parse
|
21
|
-
@parser.parse!
|
22
|
-
@config
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|