This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "cart_calculator" | |
RSpec.describe CartCalculator do | |
let(:products) do | |
[ | |
{ name: "Book", price: 20 }, | |
{ name: "Pen", price: 5 }, | |
{ name: "Notebook", price: 15 } | |
] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CartCalculator | |
def initialize(products) | |
@products = products | |
end | |
# Calculate the total price including: | |
# - Sum of all product prices | |
# - Apply bulk discount: 10% off when total exceeds $100 | |
# - Apply free shipping when total exceeds $50 (shipping cost is $10) | |
# Return a hash containing subtotal, discount, shipping, and final total |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date = Time.zone.parse("2023-11-23") | |
MemberSignup.completed | |
.where(created_at: date.beginning_of_day..date.end_of_day) | |
.where("pg_data ->> 'funnel' = ?", "default") | |
.order(created_at: :asc) | |
.map { |ms| [ms.created_at.to_s, ms.id, ms.pg_data["funnel"], ms.pg_data["signupConfirmationJson"]["client_id"]] } | |
.each { |ms| puts ms.to_s } && nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TennisGame1 | |
POINTS_NAMES = { | |
0 => 'Love', | |
1 => 'Fifteen', | |
2 => 'Thirty', | |
3 => 'Forty' | |
}.freeze | |
DEUCE = 'Deuce'.freeze | |
ADVANTAGE = 'Advantage'.freeze | |
WIN_FOR = 'Win for'.freeze |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ask_question question | |
print "#{question} " | |
return gets.chomp | |
end | |
def ask_exercise_level | |
puts "What's your exercise level (1-5)? " | |
puts ' 1. little or no exercise' | |
puts ' 2. exercise/sports 1 - 3 times per week' | |
puts ' 3. exercise/sports 4 - 5 times per week' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialize the pizzas into variables that can be read from anywhere | |
def initialize_pizzas | |
@pizza_salami = 4.0 | |
@pizza_quattro_stagioni = 8.5 | |
@pizza_ham_cheese = 6.25 | |
@pizza_shoarma = 7.3 | |
end | |
# Ask the customer's name and return it | |
def customer_name |