Christmas, this year, falls on a Wednesday!
But on which day did Christmas fall in years past?
Write a Ruby class that returns the correct weekday of Christmas Day for previous years.
| require 'bundler/inline' | |
| gemfile do | |
| source 'https://rubygems.org' | |
| gem 'sqlite3' | |
| gem 'activerecord', require: 'active_record' | |
| end | |
| # NOTE: uncomment to show logging | |
| # ActiveRecord::Base.logger = Logger.new(STDOUT) |
| class UserSubscriberService | |
| PROMO_DISCOUNT_PERCENT = Rational(85, 100) # 15% OFF | |
| PREMIUM_PLAN_NAME = 'premium_plan' | |
| def self.call(user) | |
| plan = Plan.find_by(name: PREMIUM_PLAN_NAME) | |
| user.build_subscription | |
| user.subscription.plan = plan | |
| user.subscription.amount = plan.amount * PROMO_DISCOUNT_PERCENT |
| class UserSubscriberService < ServiceBase | |
| def call(user:, subscription_plan_name:, discount_code:, cadence_months: 1) | |
| @user = user | |
| @subscription_plan = SubscriptionPlan.active.where(name: subscription_plan_name).take | |
| @discount = Discount.find_by(code: discount_code) | |
| if @subscription_plan.name == 'free' | |
| @user.subscriptions.create!( | |
| plan: @subscription_plan, | |
| cadence_months: cadence_months, |
| require 'bundler/inline' | |
| gemfile do | |
| source "https://rubygems.org" | |
| gem "money", require: "money" | |
| gem "minitest" | |
| gem "mocha" | |
| end | |
| # Calculate the current lifetime value of a user based on how much content they have generated |
| describe "PATCH /settings" do | |
| context "as a partner" do | |
| it "behaves like a user without access" do | |
| user = create(:partner, company:) | |
| params = { company: { website: "https://domain.suffix" } } | |
| headers = { "Accept" => "text/vnd.turbo-stream.html" } | |
| patch(settings_path, params: params, headers: headers) | |
| expect(response).to be_unauthorized | |
| end |
| require 'bundler/inline' | |
| ## | |
| # Get dependencies | |
| gemfile do | |
| source 'https://rubygems.org' | |
| gem 'pg' | |
| gem 'activerecord', require: 'active_record' | |
| gem 'benchmark-ips' | |
| gem 'pry' |
| # frozen_string_literal: true | |
| source "https://rubygems.org" | |
| gem "activerecord", github: "bodacious/rails" | |
| gem "sqlite3" |
| require "bundler/inline" | |
| gemfile do | |
| gem "benchmark-ips" | |
| gem "jbuilder" | |
| gem "activesupport", require: ["active_support"] | |
| end | |
| class User | |
| attr_accessor :id, :name, :email, :password, :age, :username |
| class String | |
| def palindrome? | |
| clean_string = self.gsub(/[^\w]/, '').downcase | |
| clean_string == clean_string.reverse | |
| end | |
| end | |
| puts "madam".palindrome? # => true | |
| puts "racecar".palindrome? # => true | |
| puts "madam, . ".palindrome? # => true | |
| puts "02/02/2020".palindrome? # => true |