tg_fibonacci 1.0.3 → 1.0.4

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/tg_fib +79 -51
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4891e515933b584f6c6bd450eb36fce0abd101ddfe382a70d700e40846577771
4
- data.tar.gz: 79de5032e64f4e6cdb0d3b303c5946490898820cd3a8830d2814f798482f6a51
3
+ metadata.gz: 0bb801573867cfcfbe4ab1ff92dae470768edf287ecb25678411c18d68cc5035
4
+ data.tar.gz: ae5137e44143717c4b85a5e65efc0db191b8298d2b0a9871004023e1d3a3b7d9
5
5
  SHA512:
6
- metadata.gz: 1975d5e7543ebd3a5a049a7fe6593e1466911357981d4814ace88f487055ab4258e080f3e24af82de73fecb4411d210c19094a64afe60d815cfa500efa7750d7
7
- data.tar.gz: 1ddf4385463bdfdd11b9d567ff04b079e40aa393a662e4feba738174dc28911e93a1f44fcc229f29afedbffb354fa71380ae16ff04b4137da4ba7903074c15a0
6
+ metadata.gz: 80f080cb5d01f96fcbcc8259aa803f13b0d7c649cb132d2fbe4b6e1c15e9b67ab37ed7b3b52cd5c83cbeb2dc558e1b1ea564980707ac28774d6ab41d50f8bb7c
7
+ data.tar.gz: 72520302b550674acc31ec9e4361e31e24bc9aaa8d0d6a03f21dcbfa736b33dfe92a96c2ff0de67a27a8de59b993cf0a05f6da7d871fa5e51f5c7fd9e4a32544
data/bin/tg_fib CHANGED
@@ -1,67 +1,95 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'io/console'
4
+ require 'thor'
3
5
  require_relative '../lib/fibonacci/fibonacci'
4
6
 
5
- def help_cli
6
- <<-END_OF_STRING
7
- tg_fib Compute fibonacci numbers
7
+ class TgFib < Thor
8
+ desc "term N", "Compute fibonacci sequence up to the Nth term"
9
+ def term(n)
10
+ puts term_seq(n)
11
+ end
8
12
 
9
- Usage:
10
- tg_fib help Show this help menu
11
- tg_fib [number] Compute the fibonacci number
12
- tg_fib Enter interactive mode
13
- END_OF_STRING
14
- end
13
+ desc "max N", "Compute fibonacci sequence up to a maximum of N"
14
+ def max(n)
15
+ puts max_seq(n)
16
+ end
15
17
 
16
- def help_interactive
17
- <<-END_OF_STRING
18
- Interactive help:
18
+ desc "repl", "Run in a read-eval-print loop (default)"
19
+ def repl
20
+ loop do
21
+ puts "\nPlease enter a command: (h)elp, (q)uit"
22
+ print "> "
23
+ command = STDIN.gets.chomp.downcase
24
+ case command
25
+ when /^m\s+\d+$/, /^max\s+\d+$/
26
+ puts max_seq(command.split(' ').last)
27
+ when /^t\s+\d+$/, /^term\s+\d+$/
28
+ puts term_seq(command.split(' ').last)
29
+ when 'h', 'help'
30
+ puts interactive_help
31
+ when 'q', 'quit', 'exit'
32
+ break
33
+ else
34
+ puts "Please a valid command"
35
+ end
36
+ end
37
+ end
19
38
 
20
- Commands:
21
- (h)elp Show this help menu
22
- (q)uit Quit the program
39
+ default_task :repl
23
40
 
24
- Usage:
25
- Enter a non-negative integer to compute that fibonacci number.
41
+ no_commands do
42
+ def sequence(number)
43
+ Fibonacci::Fibonacci.sequence(Integer(number))
44
+ end
26
45
 
27
- Example:
28
- > 5
29
- # => fib(5) = 1, 1, 2, 3, 5, 8
30
- END_OF_STRING
31
- end
46
+ def upto(number)
47
+ Fibonacci::Fibonacci.upto(Integer(number))
48
+ end
32
49
 
33
- def repl
34
- loop do
35
- puts "\nPlease enter a non-negative integer: (h)elp, (q)uit"
36
- print "> "
37
- command = gets.chomp.downcase
38
- case command
39
- when /^\d+$/
40
- puts run(command)
41
- when 'h', 'help'
42
- puts help_interactive
43
- when 'q', 'quit', 'exit'
44
- break
45
- else
46
- puts "Please enter a number or a valid command"
47
- end
50
+ def term_seq(number)
51
+ format(sequence(number))
48
52
  end
49
- end
50
53
 
51
- def run(number)
52
- Fibonacci::Fibonacci.seq_string(Integer(number))
53
- end
54
+ def max_seq(number)
55
+ format(upto(number))
56
+ end
57
+
58
+ def format(sequence)
59
+ "{ #{sequence.join(', ')} }"
60
+ end
61
+
62
+ def interactive_help
63
+ <<~HELP
64
+ #{divider}
65
+ Interactive help:
66
+
67
+ Commands:
68
+ (h)elp # Show this help menu
69
+ (q)uit # Quit the program
70
+ (m)ax N # Compute fibonacci sequence up to a maximum of N
71
+ (t)erm N # Compute fibonacci sequence up to the Nth term"
72
+
73
+ Examples:
74
+ > max 6
75
+ # => { 1, 1, 2, 3, 5 }
76
+
77
+ > m 6
78
+ # => { 1, 1, 2, 3, 5 }
79
+
80
+ > term 6
81
+ # => { 1, 1, 2, 3, 5, 8 }
82
+
83
+ > t 6
84
+ # => { 1, 1, 2, 3, 5, 8 }
85
+ #{divider}
86
+ HELP
87
+ end
54
88
 
55
- def start
56
- argument = ARGV.shift
57
- case argument
58
- when 'help'
59
- puts help_cli
60
- when /^\d+$/
61
- puts run(argument)
62
- else
63
- repl
89
+ def divider
90
+ '=' * IO.console.winsize[1]
64
91
  end
92
+ end
65
93
  end
66
94
 
67
- start
95
+ TgFib.start(ARGV)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tg_fibonacci
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-25 00:00:00.000000000 Z
11
+ date: 2020-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec