tg_fibonacci 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/tg_fib +79 -51
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bb801573867cfcfbe4ab1ff92dae470768edf287ecb25678411c18d68cc5035
|
4
|
+
data.tar.gz: ae5137e44143717c4b85a5e65efc0db191b8298d2b0a9871004023e1d3a3b7d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
21
|
-
(h)elp Show this help menu
|
22
|
-
(q)uit Quit the program
|
39
|
+
default_task :repl
|
23
40
|
|
24
|
-
|
25
|
-
|
41
|
+
no_commands do
|
42
|
+
def sequence(number)
|
43
|
+
Fibonacci::Fibonacci.sequence(Integer(number))
|
44
|
+
end
|
26
45
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
END_OF_STRING
|
31
|
-
end
|
46
|
+
def upto(number)
|
47
|
+
Fibonacci::Fibonacci.upto(Integer(number))
|
48
|
+
end
|
32
49
|
|
33
|
-
def
|
34
|
-
|
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
|
52
|
-
|
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
|
56
|
-
|
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.
|
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-
|
11
|
+
date: 2020-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|