pbm 0.0.2 → 0.0.3
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 +4 -4
- data/bin/pbm +5 -6
- data/lib/pbm.rb +1 -22
- data/lib/pbm/all_commands.rb +14 -0
- data/lib/pbm/commands/exit.rb +15 -6
- data/lib/pbm/commands/help.rb +24 -0
- data/lib/pbm/interpreter.rb +30 -0
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 22df781981ec8cd898e835d959b5872f761ee381
|
|
4
|
+
data.tar.gz: 2f59c50181432b4c57528d2ee811acd71c08dec4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4207118c6e643e991ca0a94381513178be36909116a8bdd36f05850c962adde9e52ad2a34f3d1c913f92973bd4be1e568bce58bb10579fe933b201dbc87aa19
|
|
7
|
+
data.tar.gz: eb837f632d3163f2b90dc51bee2107a317197a989d4cabc1463597136209e054f56c497b369a4e3b89f4ddc996dbcfe3dc5d124e6053ce40b9dabb8dcd3d0039
|
data/bin/pbm
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
require 'pbm'
|
|
3
|
+
require 'pbm/interpreter'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interpreter = PBM::Interpreter.load
|
|
6
6
|
|
|
7
7
|
puts '============================='
|
|
8
8
|
puts 'PBM - Personal Budget Manager'
|
|
@@ -12,14 +12,13 @@ puts 'Type \'help\' to display a list of commands.'
|
|
|
12
12
|
puts 'Type \'exit\' to quit.'
|
|
13
13
|
puts
|
|
14
14
|
|
|
15
|
-
while
|
|
15
|
+
while interpreter.running?
|
|
16
16
|
command = gets.chomp
|
|
17
17
|
|
|
18
18
|
begin
|
|
19
|
-
|
|
19
|
+
output = interpreter.exec(command)
|
|
20
|
+
puts output if output
|
|
20
21
|
rescue => e
|
|
21
22
|
puts e.message
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
|
-
|
|
25
|
-
puts 'Closing.'
|
data/lib/pbm.rb
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class PBM
|
|
4
|
-
attr_writer :running
|
|
5
|
-
|
|
6
|
-
def initialize
|
|
7
|
-
@running = true
|
|
8
|
-
@commands = {
|
|
9
|
-
:exit => Exit.new(self)
|
|
10
|
-
}
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def exec command
|
|
14
|
-
command.to_sym.tap do |c|
|
|
15
|
-
raise "#{c}: invalid command." unless @commands.has_key?(c)
|
|
16
|
-
@commands[c].run
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def running?
|
|
21
|
-
!!@running
|
|
22
|
-
end
|
|
1
|
+
module PBM
|
|
23
2
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module PBM
|
|
2
|
+
class AllCommands
|
|
3
|
+
class << self
|
|
4
|
+
def load(interpreter)
|
|
5
|
+
Hash[Dir[File.dirname(__FILE__) + '/commands/*.rb'].map do |file|
|
|
6
|
+
require file
|
|
7
|
+
command = file.split('/').last.split('.').first
|
|
8
|
+
class_name = "PBM::Commands::#{command.capitalize}"
|
|
9
|
+
[command.to_sym, Object.const_get(class_name).new(interpreter)]
|
|
10
|
+
end]
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/pbm/commands/exit.rb
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
module PBM
|
|
2
|
+
module Commands
|
|
3
|
+
class Exit
|
|
4
|
+
def initialize(interpreter)
|
|
5
|
+
@interpreter = interpreter
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def description
|
|
9
|
+
'exit - closes this application'
|
|
10
|
+
end
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
def run
|
|
13
|
+
@interpreter.running = false
|
|
14
|
+
'Closing.'
|
|
15
|
+
end
|
|
16
|
+
end
|
|
8
17
|
end
|
|
9
18
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module PBM
|
|
2
|
+
module Commands
|
|
3
|
+
class Help
|
|
4
|
+
def initialize(interpreter)
|
|
5
|
+
@interpreter = interpreter
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def description
|
|
9
|
+
'help - displays this help'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def run
|
|
13
|
+
<<-HELP.gsub(/^ {10}/, '')
|
|
14
|
+
|
|
15
|
+
List of commands:
|
|
16
|
+
-----------------
|
|
17
|
+
|
|
18
|
+
#{@interpreter.commands.values.map(&:description).sort.join("\n")}
|
|
19
|
+
|
|
20
|
+
HELP
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'pbm/all_commands'
|
|
2
|
+
|
|
3
|
+
module PBM
|
|
4
|
+
class Interpreter
|
|
5
|
+
class << self
|
|
6
|
+
def load
|
|
7
|
+
self.new.tap do |interpreter|
|
|
8
|
+
interpreter.commands = AllCommands.load(interpreter)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
attr_writer :running
|
|
14
|
+
attr_accessor :commands
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
@running = true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def exec command
|
|
21
|
+
command = command.to_sym
|
|
22
|
+
raise "#{command}: invalid command." unless @commands.has_key?(command)
|
|
23
|
+
@commands[command].run
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def running?
|
|
27
|
+
!!@running
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pbm
|
|
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
|
- Tarso Aires
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-05-
|
|
11
|
+
date: 2015-05-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description:
|
|
13
|
+
description: Command line application for personal budget management
|
|
14
14
|
email: tnaires@gmail.com
|
|
15
15
|
executables:
|
|
16
16
|
- pbm
|
|
@@ -19,7 +19,10 @@ extra_rdoc_files: []
|
|
|
19
19
|
files:
|
|
20
20
|
- bin/pbm
|
|
21
21
|
- lib/pbm.rb
|
|
22
|
+
- lib/pbm/all_commands.rb
|
|
22
23
|
- lib/pbm/commands/exit.rb
|
|
24
|
+
- lib/pbm/commands/help.rb
|
|
25
|
+
- lib/pbm/interpreter.rb
|
|
23
26
|
homepage: http://rubygems.org/gems/pbm
|
|
24
27
|
licenses:
|
|
25
28
|
- MIT
|