discrete_math 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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/discrete_math.rb +6 -50
- data/lib/helpers/menus/menu_helpers.rb +46 -0
- data/lib/modules/menus/menu.rb +54 -0
- data/lib/modules/menus/submenu_demo.rb +40 -0
- data/lib/modules/menus/submenu_help.rb +37 -0
- data/lib/modules/{discrete_math_topics.rb → topics/discrete_math_topics.rb} +21 -1
- metadata +7 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95fe313a20fd00b1257ce3ee13d19acb786c0729
|
4
|
+
data.tar.gz: d4b6b3c748543c6d863bf3130259116098929180
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82917bee86d8614a0ac09bc2478e4ef6fdfe1c3e19fd2103ecd59dbfa57b15bef4f0999276bd7efd68c0340969779a0100388592929caa2cf2720c8481b489c0
|
7
|
+
data.tar.gz: fff013ad3ed58a972f44dded130a03fc76ef15cf30f611d57e63dd90617f6c3dc0d9c10ecd84da79d50876f89a301ece2de67e5360da75575df679defb924465
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/discrete_math.rb
CHANGED
@@ -1,53 +1,7 @@
|
|
1
|
-
require_relative './modules/
|
1
|
+
require_relative './modules/menus/menu'
|
2
2
|
|
3
3
|
module DiscreteMath
|
4
|
-
|
5
|
-
include DiscreteMathTopics::PreliminaryMath # AbsoluteValuesDemo
|
6
|
-
include DiscreteMathTopics::PreliminaryMath::AbsoluteValuesDemo::LocationConfig # @@location_coordinates
|
7
|
-
|
8
|
-
def self.get_distance
|
9
|
-
location_first = AbsoluteValuesDemo::Location.new(@@location_coordinates[:sydney])
|
10
|
-
location_second = AbsoluteValuesDemo::Location.new(@@location_coordinates[:melbourne])
|
11
|
-
route_first = AbsoluteValuesDemo::Route.new(location_first, location_second)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
module Menu
|
16
|
-
include DiscreteMathTopics::PreliminaryMath::AbsoluteValuesDemo::LocationConfig # @@location_coordinates
|
17
|
-
|
18
|
-
USER_OPTIONS = {
|
19
|
-
"1": :demo_power_of
|
20
|
-
}
|
21
|
-
|
22
|
-
def self.request_user_choice_demo
|
23
|
-
user_choice = ""
|
24
|
-
while not USER_OPTIONS.keys.include? user_choice.to_i
|
25
|
-
# system('clear')
|
26
|
-
if user_choice == "invalid"
|
27
|
-
puts "== Invalid option chosen. Try again ==\n"
|
28
|
-
end
|
29
|
-
puts """
|
30
|
-
Select demo number to run or 'q' to quit:\n
|
31
|
-
1) Demo power of
|
32
|
-
"""
|
33
|
-
user_choice = gets.chomp
|
34
|
-
if user_choice == "1"
|
35
|
-
puts "Calculating distance from Sydney to Melbourne..."
|
36
|
-
route_first = DiscreteMath::Power.get_distance
|
37
|
-
Menu.show_result(route_first.distance)
|
38
|
-
break
|
39
|
-
elsif user_choice == "q"
|
40
|
-
break
|
41
|
-
else
|
42
|
-
user_choice = "invalid"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.show_result(result)
|
48
|
-
puts "=====> Demo Power Of result is: #{result}"
|
49
|
-
end
|
50
|
-
end
|
4
|
+
include Menu
|
51
5
|
|
52
6
|
def self.run(arg)
|
53
7
|
ARGV << '--help' if ARGV.empty? and not arg
|
@@ -65,9 +19,11 @@ module DiscreteMath
|
|
65
19
|
puts "Gem Developer Contributor Usage: Try running 'rake discrete:run[d]' or 'ruby bin/discrete d'"
|
66
20
|
# i.e. require 'discrete_math'; DiscreteMath.run("d")
|
67
21
|
when "d", "default"
|
68
|
-
|
22
|
+
Menu.show_choices_main_menu
|
69
23
|
else
|
70
|
-
|
24
|
+
Menu.show_choices_main_menu
|
71
25
|
end
|
72
26
|
end
|
73
27
|
end
|
28
|
+
|
29
|
+
DiscreteMath.run("d")
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
require_relative '../../modules/menus/menu'
|
3
|
+
require_relative '../../modules/menus/submenu_help'
|
4
|
+
require_relative '../../modules/menus/submenu_demo'
|
5
|
+
|
6
|
+
module MenuHelpers
|
7
|
+
# Reference: https://github.com/scarsam/crypto_market/blob/master/lib/crypto_market.rb
|
8
|
+
def self.terminal_table(headings = [], *rows, &block)
|
9
|
+
Terminal::Table.new :headings => headings.to_a, :rows => rows, &block
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.clear
|
13
|
+
system('clear')
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.validate_input_for_menu_kind(menu_kind)
|
17
|
+
MenuHelpers.clear
|
18
|
+
puts "== Invalid option chosen. Try again ==\n"
|
19
|
+
Menu.show_main_menu
|
20
|
+
case menu_kind
|
21
|
+
when "main"
|
22
|
+
Menu.show_main_menu
|
23
|
+
when "sub_help"
|
24
|
+
SubmenuHelp.show_sub_menu
|
25
|
+
when "sub_demo"
|
26
|
+
SubmenuDemo.show_sub_menu
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.show_menu_for_menu_kind(menu_kind)
|
31
|
+
case menu_kind
|
32
|
+
when "main"
|
33
|
+
Menu.show_main_menu
|
34
|
+
when "sub_help"
|
35
|
+
SubmenuHelp.show_sub_menu
|
36
|
+
when "sub_demo"
|
37
|
+
SubmenuDemo.show_sub_menu
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.request_input_continue_for_menu(menu_kind)
|
42
|
+
puts "\nPress any key to continue..."
|
43
|
+
gets.chomp
|
44
|
+
MenuHelpers.show_menu_for_menu_kind(menu_kind)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative '../../helpers/menus/menu_helpers'
|
2
|
+
require_relative './submenu_help'
|
3
|
+
require_relative './submenu_demo'
|
4
|
+
|
5
|
+
module Menu
|
6
|
+
EXIT_MAIN_MENU_OPTIONS = ["3"]
|
7
|
+
|
8
|
+
def self.show_greeting
|
9
|
+
puts "Welcome to Discrete Math Demo\nEnter a number to navigate"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.exit
|
13
|
+
puts "\nThank you for trying Discrete Math Demo"
|
14
|
+
Kernel.exit(false)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.request_input_for_menu(menu_kind)
|
18
|
+
MenuHelpers.clear
|
19
|
+
MenuHelpers.show_menu_for_menu_kind(menu_kind)
|
20
|
+
puts 'Enter a number: '
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.show_main_menu
|
24
|
+
table = MenuHelpers.terminal_table do |t|
|
25
|
+
t.title = Menu.show_greeting
|
26
|
+
t.add_row [1, 'Demos']
|
27
|
+
t.add_row [2, 'Help']
|
28
|
+
t.add_row [3, 'Exit']
|
29
|
+
t.style = { all_separators: true }
|
30
|
+
end
|
31
|
+
puts table
|
32
|
+
puts ''
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.show_choices_main_menu
|
36
|
+
Menu.request_input_for_menu("main")
|
37
|
+
|
38
|
+
user_input = ""
|
39
|
+
while not EXIT_MAIN_MENU_OPTIONS.include? user_input
|
40
|
+
user_input = gets.chomp
|
41
|
+
case user_input
|
42
|
+
when "1"
|
43
|
+
SubmenuDemo.show_choices_sub_menu
|
44
|
+
when "2"
|
45
|
+
SubmenuHelp.show_choices_sub_menu
|
46
|
+
when "3"
|
47
|
+
Menu.exit
|
48
|
+
else
|
49
|
+
MenuHelpers.validate_input_for_menu_kind("main")
|
50
|
+
Menu.show_choices_main_menu
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../../helpers/menus/menu_helpers'
|
2
|
+
require_relative './menu'
|
3
|
+
require_relative '../topics/discrete_math_topics'
|
4
|
+
|
5
|
+
module SubmenuDemo
|
6
|
+
include DiscreteMathTopics::PreliminaryMath
|
7
|
+
|
8
|
+
EXIT_SUB_MENU_OPTIONS = ["2"]
|
9
|
+
|
10
|
+
def self.show_sub_menu
|
11
|
+
table = MenuHelpers.terminal_table do |t|
|
12
|
+
t.title = 'Select a number'
|
13
|
+
t.add_row [1, 'Demo Power']
|
14
|
+
t.add_row [2, 'Return to main menu']
|
15
|
+
t.style = { all_separators: true }
|
16
|
+
end
|
17
|
+
puts table
|
18
|
+
puts ''
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.show_choices_sub_menu
|
22
|
+
Menu.request_input_for_menu("sub_demo")
|
23
|
+
|
24
|
+
user_input = ""
|
25
|
+
while not EXIT_SUB_MENU_OPTIONS.include? user_input
|
26
|
+
user_input = gets.chomp
|
27
|
+
case user_input
|
28
|
+
when "1"
|
29
|
+
AbsoluteValuesDemo::Calculate.run
|
30
|
+
MenuHelpers.request_input_continue_for_menu("sub_demo")
|
31
|
+
SubmenuDemo.show_choices_sub_menu
|
32
|
+
when "2"
|
33
|
+
Menu.show_choices_main_menu
|
34
|
+
else
|
35
|
+
MenuHelpers.validate_input_for_menu_kind("sub_demo")
|
36
|
+
SubmenuDemo.show_choices_sub_menu
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative '../../helpers/menus/menu_helpers'
|
2
|
+
require_relative './menu'
|
3
|
+
|
4
|
+
module SubmenuHelp
|
5
|
+
EXIT_SUB_MENU_OPTIONS = ["2"]
|
6
|
+
|
7
|
+
def self.show_sub_menu
|
8
|
+
table = MenuHelpers.terminal_table do |t|
|
9
|
+
t.title = 'Select a number'
|
10
|
+
t.add_row [1, 'Symbols']
|
11
|
+
t.add_row [2, 'Return to main menu']
|
12
|
+
t.style = { all_separators: true }
|
13
|
+
end
|
14
|
+
puts table
|
15
|
+
puts ''
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.show_choices_sub_menu
|
19
|
+
Menu.request_input_for_menu("sub_help")
|
20
|
+
|
21
|
+
user_input = ""
|
22
|
+
while not EXIT_SUB_MENU_OPTIONS.include? user_input
|
23
|
+
user_input = gets.chomp
|
24
|
+
case user_input
|
25
|
+
when "1"
|
26
|
+
puts "Sub-set - ⊆"
|
27
|
+
MenuHelpers.request_input_continue_for_menu("sub_help")
|
28
|
+
SubmenuHelp.show_choices_sub_menu
|
29
|
+
when "2"
|
30
|
+
Menu.show_choices_main_menu
|
31
|
+
else
|
32
|
+
MenuHelpers.validate_input_for_menu_kind("sub_help")
|
33
|
+
SubmenuHelp.show_choices_sub_menu
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../../helpers/math/math_helpers'
|
2
2
|
|
3
3
|
# DiscreteMath::Preliminary
|
4
4
|
module DiscreteMathTopics
|
@@ -13,6 +13,26 @@ module DiscreteMathTopics
|
|
13
13
|
}
|
14
14
|
end
|
15
15
|
|
16
|
+
module Calculate
|
17
|
+
include LocationConfig # @@location_coordinates
|
18
|
+
|
19
|
+
def self.run
|
20
|
+
Calculate.get_distance
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get_distance
|
24
|
+
puts "\nCalculating distance from Sydney to Melbourne..."
|
25
|
+
location_first = Location.new(@@location_coordinates[:sydney])
|
26
|
+
location_second = Location.new(@@location_coordinates[:melbourne])
|
27
|
+
route_first = Route.new(location_first, location_second)
|
28
|
+
Calculate.show_result(route_first.distance)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.show_result(result)
|
32
|
+
puts "=====> Result: #{result}\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
16
36
|
class Location
|
17
37
|
attr_accessor :coordinates
|
18
38
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discrete_math
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Schoen
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
RUP9VQvKiqnZW3xf19PNWEFF3GFRr27wNxjtGyYdsI3+NM9N83clEfP900gORild
|
32
32
|
pwru5JMBqMBVtqGxaVPl+1Vi/i4QZ71P
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2017-10-
|
34
|
+
date: 2017-10-02 00:00:00.000000000 Z
|
35
35
|
dependencies: []
|
36
36
|
description: A discrete math gem
|
37
37
|
email: ltfschoen@gmail.com
|
@@ -43,7 +43,11 @@ files:
|
|
43
43
|
- bin/discrete
|
44
44
|
- lib/discrete_math.rb
|
45
45
|
- lib/helpers/math/math_helpers.rb
|
46
|
-
- lib/
|
46
|
+
- lib/helpers/menus/menu_helpers.rb
|
47
|
+
- lib/modules/menus/menu.rb
|
48
|
+
- lib/modules/menus/submenu_demo.rb
|
49
|
+
- lib/modules/menus/submenu_help.rb
|
50
|
+
- lib/modules/topics/discrete_math_topics.rb
|
47
51
|
homepage: https://github.com/ltfschoen/discrete_math
|
48
52
|
licenses:
|
49
53
|
- MIT
|
metadata.gz.sig
CHANGED
Binary file
|