Skip to content

Commit

Permalink
Merge pull request #27 from LindseyB/add-tarot-images
Browse files Browse the repository at this point in the history
Add images for all the tarot cards
  • Loading branch information
LindseyB authored May 12, 2024
2 parents 34b191d + 3a5ebfc commit 9e94264
Show file tree
Hide file tree
Showing 82 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ Returns a single suit in the form of
```bash
gcloud config set project tarot-api-316423 # set the correct project
gcloud app deploy # deploy the app
gcloud app logs tail -s default # tail the logs to make sure things are gucci
gcloud app logs tail -s default # tail the logs to make sure things are gucci
```

🍦

## Thanks

* Sinatra API template https://github.com/noplay/sinatra-api-template
* Initial tarot corpus https://github.com/dariusk/corpora
* Rider-Waite tarot images https://luciellaes.itch.io/rider-waite-smith-tarot-cards-cc0
27 changes: 27 additions & 0 deletions application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def initialize
file = File.read('tarot.json')
json = JSON.parse(file, symbolize_names: true)
@cards = json[:cards]
# populate the images
@cards.each do |card|
card[:image_path] = card_image_path(card)
end
@suits = json[:suits]
super
end
Expand All @@ -18,6 +22,29 @@ def initialize
def halt_with_404_not_found
halt 404, { message: "Not found" }.to_json
end


def card_image_path(card)
if card[:suit] == "major"
# eg "/cards/TheFool.png"
"/cards/#{card[:name].gsub(" ", "")}.png"
else
# eg "/cards/Swords09.png"
"/cards/#{card[:suit].capitalize}#{card_rank_to_int(card[:rank]).to_s.rjust(2, "0")}.png"
end
end

def card_rank_to_int(rank)
rank_map = {
"page" => 11,
"knight" => 12,
"queen" => 13,
"king" => 14
}
return rank if rank.is_a? Integer # already an int
return rank_map[rank] if rank_map[rank] # map to int
return 0 # default case, should never hit
end
end

before do
Expand Down
Empty file removed public/.keep
Empty file.
Binary file added public/cards/Cups01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Cups14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Death.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Judgement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Justice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Pentacles01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Pentacles02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Pentacles03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Pentacles04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Pentacles05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Pentacles06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Pentacles07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Pentacles08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cards/Pentacles09.png
Binary file added public/cards/Pentacles10.png
Binary file added public/cards/Pentacles11.png
Binary file added public/cards/Pentacles12.png
Binary file added public/cards/Pentacles13.png
Binary file added public/cards/Pentacles14.png
Binary file added public/cards/Strength.png
Binary file added public/cards/Swords01.png
Binary file added public/cards/Swords02.png
Binary file added public/cards/Swords03.png
Binary file added public/cards/Swords04.png
Binary file added public/cards/Swords05.png
Binary file added public/cards/Swords06.png
Binary file added public/cards/Swords07.png
Binary file added public/cards/Swords08.png
Binary file added public/cards/Swords09.png
Binary file added public/cards/Swords10.png
Binary file added public/cards/Swords11.png
Binary file added public/cards/Swords12.png
Binary file added public/cards/Swords13.png
Binary file added public/cards/Swords14.png
Binary file added public/cards/Temperance.png
Binary file added public/cards/TheChariot.png
Binary file added public/cards/TheDevil.png
Binary file added public/cards/TheEmperor.png
Binary file added public/cards/TheEmpress.png
Binary file added public/cards/TheFool.png
Binary file added public/cards/TheHangedMan.png
Binary file added public/cards/TheHermit.png
Binary file added public/cards/TheHierophant.png
Binary file added public/cards/TheHighPriestess.png
Binary file added public/cards/TheLovers.png
Binary file added public/cards/TheMagician.png
Binary file added public/cards/TheMoon.png
Binary file added public/cards/TheStar.png
Binary file added public/cards/TheSun.png
Binary file added public/cards/TheTower.png
Binary file added public/cards/TheWorld.png
Binary file added public/cards/Wands01.png
Binary file added public/cards/Wands02.png
Binary file added public/cards/Wands03.png
Binary file added public/cards/Wands04.png
Binary file added public/cards/Wands05.png
Binary file added public/cards/Wands06.png
Binary file added public/cards/Wands07.png
Binary file added public/cards/Wands08.png
Binary file added public/cards/Wands09.png
Binary file added public/cards/Wands10.png
Binary file added public/cards/Wands11.png
Binary file added public/cards/Wands12.png
Binary file added public/cards/Wands13.png
Binary file added public/cards/Wands14.png
Binary file added public/cards/WheelOfFortune.png
16 changes: 16 additions & 0 deletions spec/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ def app
expect(card["name"]).to eq "The Magician"
expect(card["suit"]).to eq "major"
expect(card["rank"]).to eq 1
expect(card["image_path"]).to eq "/cards/TheMagician.png"
end

it "returns the correct image path for a card that needs to be 0 padded" do
get "/cards/swords/9"
expect(last_response).to be_ok

card = JSON.parse(last_response.body)
expect(card["name"]).to eq "Nine of Swords"
expect(card["suit"]).to eq "swords"
expect(card["rank"]).to eq 9
expect(card["image_path"]).to eq "/cards/Swords09.png"
end

it "is case insensitive" do
Expand All @@ -44,6 +56,7 @@ def app
expect(card["name"]).to eq "Queen of Swords"
expect(card["suit"]).to eq "swords"
expect(card["rank"]).to eq "queen"
expect(card["image_path"]).to eq "/cards/Swords13.png"
end

it "returns a 404 if card not found" do
Expand Down Expand Up @@ -75,6 +88,7 @@ def app
expect(card["name"]).to eq "The Magician"
expect(card["suit"]).to eq "major"
expect(card["rank"]).to eq 1
expect(card["image_path"]).to eq "/cards/TheMagician.png"
end

it "is case insensitive" do
Expand All @@ -85,6 +99,7 @@ def app
expect(card["name"]).to eq "The Magician"
expect(card["suit"]).to eq "major"
expect(card["rank"]).to eq 1
expect(card["image_path"]).to eq "/cards/TheMagician.png"
end

it "replaces numbers with words" do
Expand All @@ -95,6 +110,7 @@ def app
expect(card["name"]).to eq "Ten of Swords"
expect(card["suit"]).to eq "swords"
expect(card["rank"]).to eq 10
expect(card["image_path"]).to eq "/cards/Swords10.png"
end

it "returns 404 if card not found" do
Expand Down

0 comments on commit 9e94264

Please sign in to comment.