logic 0.0.7 → 0.0.8

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.
Files changed (2) hide show
  1. data/bin/logic +21 -43
  2. metadata +3 -3
data/bin/logic CHANGED
@@ -1,61 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../lib")
3
3
 
4
+ require 'optparse'
4
5
  require 'rubygems'
5
6
  require 'treetop'
6
7
  require 'logic_parser'
7
8
  require 'logic_operations'
8
9
 
9
- if ARGV.length == 0 || ARGV[0] == '--help' || ARGV[0] == '-h'
10
- puts <<-HELP
11
- Usage: logic [ truth_table | mcdc_pairs ] "<decision>"'
10
+ options = {}
11
+
12
+ option_parser = OptionParser.new
12
13
 
13
- Truth tables are easy:
14
+ option_parser.banner = "Usage: logic [options] <decision>"
14
15
 
15
- logic truth_table '(a or b) and (c or d)'
16
-
17
- Gives you:
18
-
19
- a b c d | output
20
- 1) 0 0 0 0 | 0
21
- 2) 0 0 0 1 | 0
22
- 3) 0 0 1 0 | 0
23
- 4) 0 0 1 1 | 0
24
- 5) 0 1 0 0 | 0
25
- 6) 0 1 0 1 | 1
26
- 7) 0 1 1 0 | 1
27
- 8) 0 1 1 1 | 1
28
- 9) 1 0 0 0 | 0
29
- 10) 1 0 0 1 | 1
30
- 11) 1 0 1 0 | 1
31
- 12) 1 0 1 1 | 1
32
- 13) 1 1 0 0 | 0
33
- 14) 1 1 0 1 | 1
34
- 15) 1 1 1 0 | 1
35
- 16) 1 1 1 1 | 1
36
-
37
- MC/DC test case pairs can also be found:
16
+ option_parser.on( '-l', '--truth_table', 'Show the truth table for the decision' ) do
17
+ options[:truth_table] = true
18
+ end
38
19
 
39
- logic mcdc_pairs '(a or b) and (c or d)'
20
+ option_parser.on( '-m', '--mcdc_pairs', 'Show MC/DC test case pairs' ) do
21
+ options[:mcdc_pairs] = true
22
+ end
40
23
 
41
- Gives you:
24
+ option_parser.on( '-h', '--help', 'You\'re looking at it' ) do
25
+ options[:help] = true
26
+ end
42
27
 
43
- a => [[2, 10], [3, 11], [4, 12]]
44
- b => [[2, 6], [3, 7], [4, 8]]
45
- c => [[5, 7], [9, 11], [13, 15]]
46
- d => [[5, 6], [9, 10], [13, 14]]
28
+ option_parser.parse!
47
29
 
48
- HELP
49
- exit 0
30
+ if options[:help] or ARGV.length == 0
31
+ puts option_parser.help
32
+ exit
50
33
  end
51
34
 
52
35
  parser = LogicParser.new
53
- decision = parser.parse ARGV[1]
54
-
55
- if ARGV[0] == 'truth_table'
56
- puts decision.truth_table
57
- end
36
+ decision = parser.parse ARGV.join(' ')
58
37
 
59
- if ARGV[0] == 'mcdc_pairs'
60
- puts decision.mcdc_pairs
61
- end
38
+ puts decision.truth_table if options[:truth_table]
39
+ puts decision.mcdc_pairs if options[:mcdc_pairs]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bryan Ash
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-27 00:00:00 -04:00
17
+ date: 2010-04-28 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency