Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joel Davalos #398

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/card.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Card
attr_reader :suit
attr_reader :value
attr_reader :rank
def initialize(suit, value, rank)
@suit = suit
@value = value
@rank = rank
end
end
26 changes: 26 additions & 0 deletions lib/deck.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Deck
attr_reader :cards
def initialize(cards)
@cards = cards
end

def rank_of_card_at(index)
@cards[index].rank
end

def high_ranking_cards
@cards.select { |card| card.rank >=11 }
end

def perecnt_high_ranking
(high_ranking_cards.length.to.f / @cards.length * 100)
end

def remove_card
@cards.shift
end

def add_card(card)
@cards << card
end
end
3 changes: 2 additions & 1 deletion spec/card_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rspec'
require './lib/card'
require './lib/card.rb'


RSpec.describe Card do
it "exists" do
Expand Down
16 changes: 16 additions & 0 deletions spec/deck_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "./lib/card.rb"
require "./lib/deck.rb"
require "rspec"

RSpec.describe Deck do
let(:card1) { double("Card", rank: 10) }
let(:card2) { double("Card", rank: 11) }
let(:card3) { double("Card", rank: 'Ace') }
let(:cards) { [card1, card2, card3] }
let(:deck) { Deck.new(cards) }

describe "#initialize" do
it "initializes with an array of cards" do
expect(deck.cards).to eq(cards)
end
end