ascii_cards 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e82c71d3bcce40f2321a837d335e44e7777dcc81a2e070b34f6143a0fc2541b0
4
+ data.tar.gz: 83d210f0dca6825986c911c0fea0089242717defa531a0e622b714fb131340b2
5
+ SHA512:
6
+ metadata.gz: 90675bd64c0b8154ca50beb8c67892fa8e6a153241a112969610982c99c736a00e26c8d1224467f6356b4e9114657ec09faea78613153e9cd7ff0eaeaed30adf
7
+ data.tar.gz: 5d7b60d98ded5c1c361bf18c43db81d873b35f0254c9ceee4610579f06a35f21f32ddda2c0c1dcaaedc156f5d987cf2247393d2c0ea156e48fb08cc903de4f26
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ascii_cards/version'
4
+ require 'pry'
5
+
6
+ module ASCIICards
7
+ RANK_SYMBOLS = {
8
+ 2 => '2',
9
+ 3 => '3',
10
+ 4 => '4',
11
+ 5 => '5',
12
+ 6 => '6',
13
+ 7 => '7',
14
+ 8 => '8',
15
+ 9 => '9',
16
+ 10 => '10',
17
+ jack: 'J',
18
+ queen: 'Q',
19
+ king: 'K',
20
+ ace: 'A'
21
+ }.freeze
22
+
23
+ SUIT_SYMBOLS = {
24
+ spades: '♠',
25
+ diamonds: '♦',
26
+ hearts: '♥',
27
+ clubs: '♣'
28
+ }.freeze
29
+
30
+ class << self
31
+ def stringify(*cards)
32
+ join_cards(
33
+ cards.map do |rank, suit, state = :visible|
34
+ if state == :hidden
35
+ hidden_card
36
+ else
37
+ format_card(rank, suit)
38
+ end
39
+ end
40
+ )
41
+ end
42
+
43
+ private
44
+
45
+ def join_cards(cards)
46
+ first, *rest = cards.map do |card|
47
+ card.split("\n")
48
+ end
49
+
50
+ first.zip(*rest).map do |lines|
51
+ lines.join('')
52
+ end.join("\n")
53
+ end
54
+
55
+ def format_card(rank, suit)
56
+ rank_symbol = RANK_SYMBOLS.fetch(rank)
57
+ suit_symbol = SUIT_SYMBOLS.fetch(suit)
58
+
59
+ format(<<~ASCII, rank_symbol.ljust(2), suit_symbol, rank_symbol)
60
+ ┌─────────┐
61
+ │%2s │
62
+ │ │
63
+ │ │
64
+ │ %s │
65
+ │ │
66
+ │ │
67
+ │ %2s│
68
+ └─────────┘
69
+ ASCII
70
+ end
71
+
72
+ def hidden_card
73
+ <<~ASCII
74
+ ┌─────────┐
75
+ │░░░░░░░░░│
76
+ │░░░░░░░░░│
77
+ │░░░░░░░░░│
78
+ │░░░░░░░░░│
79
+ │░░░░░░░░░│
80
+ │░░░░░░░░░│
81
+ │░░░░░░░░░│
82
+ └─────────┘
83
+ ASCII
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ASCIICards
4
+ VERSION = '1.0.0'
5
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ascii_cards
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Igor S. Morozov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: igor@morozov.is
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ascii_cards.rb
20
+ - lib/ascii_cards/version.rb
21
+ homepage: https://github.com/Morozzzko/ascii_cards
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.0.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Simple yet fancy ASCII printer for playing cards
44
+ test_files: []