discrete_math 0.0.9 → 0.0.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 568926b62e6cf4dbc594e1c46539d3e2f9e2c4b5
4
- data.tar.gz: a098acdfec8ccefee7fef5e1dbc1a9af097d3a31
3
+ metadata.gz: 47abe7898521f762cbe14e4c7ecb97d2cf6d296b
4
+ data.tar.gz: a5d3d17f558564dbf46982ea99a550170067e97f
5
5
  SHA512:
6
- metadata.gz: bebaed7657f212492422334166e7fdb9bef8d04486a6fd431c4d61da3df23f975a1878da7bcea99fe94823b8cb6a08a27fde1f6db5064ec3260e4b2f9503f4ff
7
- data.tar.gz: a47de8e335a310dc394c30cbcb07ea7a7a70a38d253bb19cb33f87c808da51629a23a6b94dd60432da4a7c036363787806f614f78bf076306f24b8c0bdbd31c6
6
+ metadata.gz: 003f0890887890147b4fe53e7e9a6f3ba4320c030deb6316a67910303e4c5c50ccbb158b3f6b215ccd6360664af76e6ef760e061b3348acb022a242e0ad48cae
7
+ data.tar.gz: 2395ca7083e0cea634db87ad641bbb409527d328e59d69e40bf096422634b1953e645a95fa86fac24e168ca212dbbea1dfe4d149a3af6fe618145a937ddf9832
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -5,13 +5,14 @@ require_relative '../topics/discrete_math_topics'
5
5
  module SubmenuDemo
6
6
  include DiscreteMathTopics::PreliminaryMath
7
7
 
8
- EXIT_SUB_MENU_OPTIONS = ["2"]
8
+ EXIT_SUB_MENU_OPTIONS = ["0"]
9
9
 
10
10
  def self.show_sub_menu
11
11
  table = MenuHelpers.terminal_table do |t|
12
12
  t.title = 'Select a number'
13
- t.add_row [1, 'Demo Power']
14
- t.add_row [2, 'Return to main menu']
13
+ t.add_row [0, 'Back to main menu']
14
+ t.add_row [1, 'Demo SHA-256 Checksum']
15
+ t.add_row [2, 'Demo Power']
15
16
  t.style = { all_separators: true }
16
17
  end
17
18
  puts table
@@ -25,12 +26,16 @@ module SubmenuDemo
25
26
  while not EXIT_SUB_MENU_OPTIONS.include? user_input
26
27
  user_input = gets.chomp
27
28
  case user_input
29
+ when "0"
30
+ Menu.show_choices_main_menu
28
31
  when "1"
29
- AbsoluteValuesDemo::Calculate.run
32
+ ShasumDemo.run
30
33
  MenuHelpers.request_input_continue_for_menu("sub_demo")
31
34
  SubmenuDemo.show_choices_sub_menu
32
35
  when "2"
33
- Menu.show_choices_main_menu
36
+ PowersDemo::Calculate.run
37
+ MenuHelpers.request_input_continue_for_menu("sub_demo")
38
+ SubmenuDemo.show_choices_sub_menu
34
39
  else
35
40
  MenuHelpers.validate_input_for_menu_kind("sub_demo")
36
41
  SubmenuDemo.show_choices_sub_menu
@@ -7,8 +7,8 @@ module SubmenuHelp
7
7
  def self.show_sub_menu
8
8
  table = MenuHelpers.terminal_table do |t|
9
9
  t.title = 'Select a number'
10
+ t.add_row [0, 'Back to main menu']
10
11
  t.add_row [1, 'Symbols']
11
- t.add_row [2, 'Return to main menu']
12
12
  t.style = { all_separators: true }
13
13
  end
14
14
  puts table
@@ -22,12 +22,12 @@ module SubmenuHelp
22
22
  while not EXIT_SUB_MENU_OPTIONS.include? user_input
23
23
  user_input = gets.chomp
24
24
  case user_input
25
+ when "0"
26
+ Menu.show_choices_main_menu
25
27
  when "1"
26
28
  puts "Sub-set - ⊆"
27
29
  MenuHelpers.request_input_continue_for_menu("sub_help")
28
30
  SubmenuHelp.show_choices_sub_menu
29
- when "2"
30
- Menu.show_choices_main_menu
31
31
  else
32
32
  MenuHelpers.validate_input_for_menu_kind("sub_help")
33
33
  SubmenuHelp.show_choices_sub_menu
@@ -0,0 +1,55 @@
1
+ require_relative '../../../helpers/math/math_helpers'
2
+
3
+ module PowersDemo
4
+
5
+ module LocationConfig
6
+ @@location_coordinates = {
7
+ sydney: { x: -100, y: -100 },
8
+ brisbane: { x: 100, y: 100 },
9
+ melbourne: { x: 200, y: 200 }
10
+ }
11
+ end
12
+
13
+ module Calculate
14
+ include LocationConfig # @@location_coordinates
15
+
16
+ def self.run
17
+ Calculate.get_distance
18
+ end
19
+
20
+ def self.get_distance
21
+ puts "\nCalculating distance from Sydney to Melbourne..."
22
+ location_first = Location.new(@@location_coordinates[:sydney])
23
+ location_second = Location.new(@@location_coordinates[:melbourne])
24
+ route_first = Route.new(location_first, location_second)
25
+ Calculate.show_result(route_first.distance)
26
+ end
27
+
28
+ def self.show_result(result)
29
+ puts "=====> Result: #{result}\n"
30
+ end
31
+ end
32
+
33
+ class Location
34
+ attr_accessor :coordinates
35
+
36
+ def initialize(coordinates)
37
+ @coordinates = coordinates
38
+ end
39
+ end
40
+
41
+ class Route
42
+ attr_reader :distance
43
+
44
+ def initialize(start_location, finish_location)
45
+ @start_location = start_location
46
+ @finish_location = finish_location
47
+ end
48
+
49
+ def distance
50
+ dist_x = @start_location.coordinates[:x] - @finish_location.coordinates[:x]
51
+ dist_y = @start_location.coordinates[:y] - @finish_location.coordinates[:y]
52
+ dist_total = MathHelpers.pythagoras_theorem(dist_x, dist_y)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,48 @@
1
+ require 'rest-client'
2
+ require 'digest'
3
+
4
+ module ShasumDemo
5
+ def self.run
6
+ puts "\nChoose a Gem from RubyGems to validate its the Checksum of its SHA-256"
7
+ puts "- Enter name of Gem (i.e. rails): "
8
+ gem_name = gets.chomp.downcase.strip
9
+ puts "Enter version of Gem (i.e. 5.1.2): "
10
+ gem_version = gets.chomp.strip
11
+ valid_shasum?(gem_name, gem_version)
12
+ end
13
+
14
+ def self.is_gem?(gem_name, gem_version)
15
+ puts "Please wait. Checking that given version exists for gem"
16
+ response = %x[gem search '^#{gem_name}$' --all]
17
+ if response != "\n"
18
+ gem_versions_list = response[response.index('(')+1..response.index(')')-1].split(',').map {|ver| ver.strip }
19
+ return (gem_versions_list.include? gem_version) ? true : false
20
+ else
21
+ puts "\nNo versions of the gem exist"
22
+ return false
23
+ end
24
+ end
25
+
26
+ def self.get_checksum_for_gem(gem_name, gem_version)
27
+ puts "\nObtaining actual checksum SHA 256 for #{gem_name} gem version #{gem_version}"
28
+ raw = RestClient::Request.execute(
29
+ method: :get,
30
+ url: "https://rubygems.org/downloads/#{gem_name}-#{gem_version}.gem",
31
+ raw_response: true)
32
+ Digest::SHA256.file(raw.file.path).hexdigest
33
+ end
34
+
35
+ def self.valid_shasum?(gem_name, gem_version)
36
+ is_gem = is_gem?(gem_name, gem_version)
37
+ return false if not is_gem
38
+ expected_checksum = get_checksum_for_gem(gem_name, gem_version)
39
+ puts "Please wait. Downloading gem into subfolder ./temp"
40
+ %x[mkdir -p temp; cd temp; gem fetch #{gem_name} --version '#{gem_version}';]
41
+ output = %x[cd temp; shasum -a 256 ./#{gem_name}-#{gem_version}.gem]
42
+ actual_checksum = output.split[0] # split on space
43
+ puts "Actual Checksum: #{actual_checksum}"
44
+ puts "Expected Checksum: #{expected_checksum}"
45
+ puts "Valid Checksum: #{actual_checksum == expected_checksum}"
46
+ actual_checksum == expected_checksum
47
+ end
48
+ end
@@ -1,60 +1,10 @@
1
- require_relative '../../helpers/math/math_helpers'
1
+ require_relative './demos/powers_demo'
2
+ require_relative './demos/shasum_demo'
2
3
 
3
4
  # DiscreteMath::Preliminary
4
5
  module DiscreteMathTopics
5
6
  module PreliminaryMath
6
- module AbsoluteValuesDemo
7
-
8
- module LocationConfig
9
- @@location_coordinates = {
10
- sydney: { x: -100, y: -100 },
11
- brisbane: { x: 100, y: 100 },
12
- melbourne: { x: 200, y: 200 }
13
- }
14
- end
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
-
36
- class Location
37
- attr_accessor :coordinates
38
-
39
- def initialize(coordinates)
40
- @coordinates = coordinates
41
- end
42
- end
43
-
44
- class Route
45
- attr_reader :distance
46
-
47
- def initialize(start_location, finish_location)
48
- @start_location = start_location
49
- @finish_location = finish_location
50
- end
51
-
52
- def distance
53
- dist_x = @start_location.coordinates[:x] - @finish_location.coordinates[:x]
54
- dist_y = @start_location.coordinates[:y] - @finish_location.coordinates[:y]
55
- dist_total = MathHelpers.pythagoras_theorem(dist_x, dist_y)
56
- end
57
- end
58
- end
7
+ include PowersDemo
8
+ include ShasumDemo
59
9
  end
60
10
  end
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.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Schoen
@@ -13,23 +13,23 @@ cert_chain:
13
13
  -----BEGIN CERTIFICATE-----
14
14
  MIIDdDCCAlygAwIBAgIBATANBgkqhkiG9w0BAQUFADBAMRIwEAYDVQQDDAlsdGZz
15
15
  Y2hvZW4xFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
16
- bTAeFw0xNzEwMDExNDEzMjlaFw0xODEwMDExNDEzMjlaMEAxEjAQBgNVBAMMCWx0
16
+ bTAeFw0xNzEwMDExNDUxMDlaFw0xODEwMDExNDUxMDlaMEAxEjAQBgNVBAMMCWx0
17
17
  ZnNjaG9lbjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYD
18
- Y29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0uYvOoUDKp4nKLtU
19
- 5AYowoPCbq+WiXNfXovv73jgKymVh1gmr7at9sjy0+mhrb+jaI7oi2zK4i7r0Z9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FF9Vl8CeF1YhRwdtYAtDyNCvktAad5vs9PXDDl6KxxR6I
28
- 5AhEWo+o/QTbQtm+76ZzYHy0LkuMDDpCzFDppk7KHyMHmIpynzRodxfg1SFpBvhU
29
- 2/2Dgywxyzmer8W1BB61jbBut6wycj++2mn9EUZpMG9fG3kKJxvY8TFTz1r5ObsI
30
- fowVRzzhVCKI+ubuS/omPbKEKqrhiYI9w4EGCqB9LaGkqRxVNkFz5qb0EpUstjyA
31
- LIBjwJiQo7aFPbfaYoAJ7FdmhvwfIt7Badk+6OP60U8vsUyOxLN1uNi0S1VObQYr
32
- tJitJ5nXK6A59IDMzde8gqREO79utf2N
27
+ BQUAA4IBAQAuGY9nejO75JtOCZAZ46aZKIH6rZiKKV5sgRSbeDg0+yuE1kQ3KSA1
28
+ H0iIY74Sr6Z3C/M5os53OxIgDJ6+NUeO4U+1k4/4LPVIbYickDMhNJaffi52nfDa
29
+ kVqcfCAr4CHXePZNmOGzop3E8XTiuN/3noE+CkMxIc9FULcQWYRQQHXJQW9LDfNA
30
+ wxesPDlbmlG0uSZIvsdakx68lzZpD/tNzmYxh2f8CV/wmo9x8svsZJz2NzTxVdsZ
31
+ XzRCa0YFMPhgq166ppJ94lAe6lwcXsAeqpPGhMdSObkaGh1a7roPZNF9hJndAVal
32
+ 8wouMk3fg6WNsBHgscrSCZLkysvh3wD5
33
33
  -----END CERTIFICATE-----
34
34
  date: 2017-10-02 00:00:00.000000000 Z
35
35
  dependencies: []
@@ -47,6 +47,8 @@ files:
47
47
  - lib/modules/menus/menu.rb
48
48
  - lib/modules/menus/submenu_demo.rb
49
49
  - lib/modules/menus/submenu_help.rb
50
+ - lib/modules/topics/demos/powers_demo.rb
51
+ - lib/modules/topics/demos/shasum_demo.rb
50
52
  - lib/modules/topics/discrete_math_topics.rb
51
53
  homepage: https://github.com/ltfschoen/discrete_math
52
54
  licenses:
metadata.gz.sig CHANGED
Binary file