Skip to content

Commit 5294eac

Browse files
committed
Explaining variable exercise
0 parents  commit 5294eac

File tree

8 files changed

+89
-0
lines changed

8 files changed

+89
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
!.keep
2+
*.DS_Store
3+
*.swo
4+
*.swp
5+
.bundle
6+
tags
7+
vendor

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rake'
4+
gem 'rspec'

Gemfile.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
diff-lcs (1.2.5)
5+
rake (10.3.2)
6+
rspec (3.1.0)
7+
rspec-core (~> 3.1.0)
8+
rspec-expectations (~> 3.1.0)
9+
rspec-mocks (~> 3.1.0)
10+
rspec-core (3.1.7)
11+
rspec-support (~> 3.1.0)
12+
rspec-expectations (3.1.2)
13+
diff-lcs (>= 1.2.0, < 2.0)
14+
rspec-support (~> 3.1.0)
15+
rspec-mocks (3.1.3)
16+
rspec-support (~> 3.1.0)
17+
rspec-support (3.1.2)
18+
19+
PLATFORMS
20+
ruby
21+
22+
DEPENDENCIES
23+
rake
24+
rspec

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env rake
2+
3+
require 'rspec/core/rake_task'
4+
5+
RSpec::Core::RakeTask.new(:spec)
6+
7+
task default: :spec

bin/setup

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env sh
2+
3+
# Run this script immediately after cloning the codebase.
4+
# https://github.com/thoughtbot/guides/tree/master/protocol
5+
6+
# Exit if any subcommand fails
7+
set -e
8+
9+
# Set up Ruby dependencies via Bundler
10+
bundle install

lib/tipper.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Tipper
2+
TAX = 0.05
3+
4+
def initialize(amount:, discount_percentage: 0, tip_percentage:)
5+
@amount = amount
6+
@discount_percentage = discount_percentage
7+
@tip_percentage = tip_percentage
8+
end
9+
10+
def total
11+
amount + (amount * TAX) - (amount * (discount_percentage / 100.0)) + (amount * (tip_percentage / 100.0))
12+
end
13+
14+
private
15+
16+
attr_reader :amount, :discount_percentage, :tip_percentage
17+
end

spec/lib/tipper_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper'
2+
3+
describe Tipper do
4+
describe '#total' do
5+
it 'returns the total due with tax and tip' do
6+
tipper = Tipper.new(amount: 100, tip_percentage: 20)
7+
expect(tipper.total).to eq 125
8+
end
9+
10+
it 'returns the total due with tax, discount, and tip' do
11+
tipper = Tipper.new(amount: 100, discount_percentage: 20, tip_percentage: 20)
12+
expect(tipper.total).to eq 105
13+
end
14+
end
15+
end

spec/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PROJECT_ROOT = File.expand_path("../..", __FILE__)
2+
3+
Dir.glob(File.join(PROJECT_ROOT, "lib", "*.rb")).each do |file|
4+
require file
5+
end

0 commit comments

Comments
 (0)