From 00d58aeae091059a419d6cff92dae87ec9b22ef0 Mon Sep 17 00:00:00 2001 From: Saud Date: Wed, 5 Jul 2017 23:25:29 +0000 Subject: [PATCH 1/8] I think I solved the first part --- app/controllers/calculations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 0df2d0f..d087423 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -11,7 +11,7 @@ def word_count # ================================================================================ - @word_count = "Replace this string with your answer." + @word_count = @text.split.count @character_count_with_spaces = "Replace this string with your answer." From 2fff230c95a7277d6d6e3dd2d3500f696ad96088 Mon Sep 17 00:00:00 2001 From: Saud Date: Wed, 5 Jul 2017 23:46:59 +0000 Subject: [PATCH 2/8] Solved 2 and 3 --- app/controllers/calculations_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index d087423..eb7e865 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -13,11 +13,11 @@ def word_count @word_count = @text.split.count - @character_count_with_spaces = "Replace this string with your answer." + @character_count_with_spaces = @text.size - @character_count_without_spaces = "Replace this string with your answer." + @character_count_without_spaces = @text.gsub(" ","").size - @occurrences = "Replace this string with your answer." + @occurrences = "hello" # ================================================================================ # Your code goes above. From daa338f979cd9b0b0f7f65306741dea6a3a282a1 Mon Sep 17 00:00:00 2001 From: Saud Date: Thu, 6 Jul 2017 00:03:11 +0000 Subject: [PATCH 3/8] Made a change for #4 --- app/controllers/calculations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index eb7e865..0552bcc 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -17,7 +17,7 @@ def word_count @character_count_without_spaces = @text.gsub(" ","").size - @occurrences = "hello" + @occurrences = @text.count(@special_word) # ================================================================================ # Your code goes above. From 9e572f33385b3d62f9b8ae7d356e0d03d95a27aa Mon Sep 17 00:00:00 2001 From: Saud Date: Thu, 6 Jul 2017 00:09:28 +0000 Subject: [PATCH 4/8] Word Count Completed --- app/controllers/calculations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 0552bcc..fd31089 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -17,7 +17,7 @@ def word_count @character_count_without_spaces = @text.gsub(" ","").size - @occurrences = @text.count(@special_word) + @occurrences = @text.split.count(@special_word) # ================================================================================ # Your code goes above. From 4fd6038d4b79fa06c79cb1b809ace7ab801d9d20 Mon Sep 17 00:00:00 2001 From: Saud Date: Thu, 6 Jul 2017 00:24:39 +0000 Subject: [PATCH 5/8] Loan payment calculation completed --- app/controllers/calculations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index fd31089..8092dec 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -38,7 +38,7 @@ def loan_payment # The principal value the user input is in the decimal @principal. # ================================================================================ - @monthly_payment = "Replace this string with your answer." + @monthly_payment = (@principal*((1+(@apr/100))**(@years)))/(@years*12) # ================================================================================ # Your code goes above. From 55b67e56f112b09d9c10a7e91baa60b4b51e6b26 Mon Sep 17 00:00:00 2001 From: Saud Date: Thu, 6 Jul 2017 01:03:29 +0000 Subject: [PATCH 6/8] Addressed special characters in word calculator, completed monthly payment calculator --- app/controllers/calculations_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 8092dec..35fa085 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -17,7 +17,7 @@ def word_count @character_count_without_spaces = @text.gsub(" ","").size - @occurrences = @text.split.count(@special_word) + @occurrences = @text.downcase.gsub(/[^a-z0-9\s]/i,"").split.count(@special_word.downcase) # ================================================================================ # Your code goes above. @@ -38,7 +38,8 @@ def loan_payment # The principal value the user input is in the decimal @principal. # ================================================================================ - @monthly_payment = (@principal*((1+(@apr/100))**(@years)))/(@years*12) + @apr_decimal = @apr/1200 + @monthly_payment = (@apr_decimal/(1-(1+@apr_decimal)**(-1*@years*12)))*@principal # ================================================================================ # Your code goes above. From b6bfbaa946699674d88a70fe939cd417ffc84d68 Mon Sep 17 00:00:00 2001 From: Saud Date: Thu, 6 Jul 2017 01:59:45 +0000 Subject: [PATCH 7/8] Made changes for date difference calculator --- Gemfile | 3 +++ Gemfile.lock | 8 ++++++++ app/assets/javascripts/application.js | 7 +++++++ app/controllers/calculations_controller.rb | 12 ++++++------ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index b625ba3..86f60d3 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,9 @@ git_source(:github) do |repo_name| "https://github.com/#{repo_name}.git" end +gem 'momentjs-rails' +gem 'bootstrap3-datetimepicker-rails' +gem 'chronic' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.2' diff --git a/Gemfile.lock b/Gemfile.lock index a4b753b..d911ad9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,8 @@ GEM bootstrap (4.0.0.alpha6) autoprefixer-rails (>= 6.0.3) sass (>= 3.4.19) + bootstrap3-datetimepicker-rails (4.17.47) + momentjs-rails (>= 2.8.1) builder (3.2.3) byebug (9.0.6) callsite (0.0.11) @@ -85,6 +87,7 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + chronic (0.10.2) coderay (1.1.1) concurrent-ruby (1.0.5) crack (0.4.3) @@ -140,6 +143,8 @@ GEM mime-types-data (3.2016.0521) mini_portile2 (2.2.0) minitest (5.10.2) + momentjs-rails (2.17.1) + railties (>= 3.1) multi_json (1.12.1) nio4r (2.1.0) nokogiri (1.8.0) @@ -262,8 +267,10 @@ DEPENDENCIES better_errors binding_of_caller bootstrap (~> 4.0.0.alpha6) + bootstrap3-datetimepicker-rails byebug capybara + chronic dotenv-rails factory_girl_rails firstdraft_generators @@ -274,6 +281,7 @@ DEPENDENCIES letter_opener listen (>= 3.0.5, < 3.2) meta_request + momentjs-rails pry-rails puma (~> 3.7) rails (~> 5.1.2) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 739c2fe..da0725c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,3 +14,10 @@ //= require bootstrap //= require turbolinks //= require_tree . +//= require jquery +//= require moment +//= require bootstrap-datetimepicker + +$(function () { + $('.datetimepicker').datetimepicker(); +}); \ No newline at end of file diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 35fa085..16df316 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -61,12 +61,12 @@ def time_between # number of seconds as a result. # ================================================================================ - @seconds = "Replace this string with your answer." - @minutes = "Replace this string with your answer." - @hours = "Replace this string with your answer." - @days = "Replace this string with your answer." - @weeks = "Replace this string with your answer." - @years = "Replace this string with your answer." + @seconds = @ending-@starting + @minutes = @seconds/60 + @hours = @minutes/60 + @days = @hours/24 + @weeks = @days/7 + @years = @weeks/52 # ================================================================================ # Your code goes above. From 437fcfa5be69bb8bab8f0f3dadc52e12c6cade36 Mon Sep 17 00:00:00 2001 From: Saud Date: Thu, 6 Jul 2017 02:12:45 +0000 Subject: [PATCH 8/8] More progress on date difference calculator --- app/controllers/calculations_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb index 16df316..f143fcc 100644 --- a/app/controllers/calculations_controller.rb +++ b/app/controllers/calculations_controller.rb @@ -66,7 +66,7 @@ def time_between @hours = @minutes/60 @days = @hours/24 @weeks = @days/7 - @years = @weeks/52 + @years = @weeks/52 #hopefully this is done # ================================================================================ # Your code goes above.