cw_card_utils 0.1.9 → 0.1.10
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.
- checksums.yaml +4 -4
- data/README.md +52 -23
- data/lib/cw_card_utils/deck_comparator.rb +1 -1
- data/lib/cw_card_utils/decklist_parser/card.rb +2 -2
- data/lib/cw_card_utils/decklist_parser/parser.rb +2 -2
- data/lib/cw_card_utils/scryfall_cmc_data.rb +2 -2
- data/lib/cw_card_utils/version.rb +1 -1
- data/lib/cw_card_utils.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0aab3de52c635cd3e24f8ba808777bfc5e60cb07b0e2f02357c67f00212dcfc9
|
4
|
+
data.tar.gz: 28d0d647d3c6f91a69b6853abcd73605e9f116a8251afff8c5f39a7cf77b22fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42be3567474156c9c6417d0c7994485567608af868a3f8dadd832b964c99216397bda74d89e83210c3e170ba1b5d4dddef19c401efc70eb7380dfe8068753c7b
|
7
|
+
data.tar.gz: 4218005f3d49d44613e738b2f718f5f1997a314ec81918d865f9bec17b714b6c811f9dfcc2fd6a79ced057175fa8bfc69e15e8f3d0b981b4b7c00d52cb3014af
|
data/README.md
CHANGED
@@ -1,50 +1,79 @@
|
|
1
1
|
# CwCardUtils
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cw_card_utils`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
A Ruby gem for analyzing Magic: The Gathering decklists and calculating various metrics.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cw_card_utils'
|
11
|
+
```
|
10
12
|
|
11
|
-
|
13
|
+
And then execute:
|
12
14
|
|
13
15
|
```bash
|
14
|
-
bundle
|
16
|
+
bundle install
|
15
17
|
```
|
16
18
|
|
17
|
-
|
19
|
+
## Configuration
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
You can configure the card data source used by the library:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# In a Rails initializer (config/initializers/cw_card_utils.rb)
|
25
|
+
CwCardUtils.configure do |config|
|
26
|
+
config.card_data_source = MyCustomDataSource.new
|
27
|
+
end
|
28
|
+
|
29
|
+
# Or set it directly
|
30
|
+
CwCardUtils.card_data_source = MyCustomDataSource.new
|
21
31
|
```
|
22
32
|
|
33
|
+
The default data source is `CwCardUtils::ScryfallCmcData.instance`, which loads card data from a local JSON file.
|
34
|
+
|
23
35
|
## Usage
|
24
36
|
|
25
|
-
|
37
|
+
### Basic Deck Parsing
|
26
38
|
|
27
|
-
|
39
|
+
```ruby
|
40
|
+
require 'cw_card_utils'
|
28
41
|
|
29
|
-
|
42
|
+
# Parse a decklist
|
43
|
+
decklist = <<~DECK
|
44
|
+
4 Lightning Bolt
|
45
|
+
4 Mountain
|
46
|
+
2 Shock
|
47
|
+
DECK
|
30
48
|
|
31
|
-
|
49
|
+
deck = CwCardUtils::DecklistParser::Parser.new(decklist).parse
|
32
50
|
|
33
|
-
|
51
|
+
# Access deck information
|
52
|
+
puts deck.mainboard_size # => 10
|
53
|
+
puts deck.color_identity # => ["R"]
|
54
|
+
puts deck.archetype # => :aggro
|
55
|
+
```
|
34
56
|
|
35
|
-
|
57
|
+
### Custom Data Sources
|
36
58
|
|
37
|
-
|
59
|
+
You can implement your own card data source by inheriting from `CwCardUtils::CardDataSource`:
|
38
60
|
|
39
|
-
|
61
|
+
```ruby
|
62
|
+
class MyCustomDataSource < CwCardUtils::CardDataSource
|
63
|
+
def find_card(name)
|
64
|
+
# Your implementation here
|
65
|
+
# Should return a hash with card data or nil
|
66
|
+
end
|
67
|
+
end
|
40
68
|
|
41
|
-
|
69
|
+
# Configure the library to use your data source
|
70
|
+
CwCardUtils.card_data_source = MyCustomDataSource.new
|
71
|
+
```
|
42
72
|
|
43
|
-
|
73
|
+
## Development
|
44
74
|
|
45
|
-
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
76
|
|
47
|
-
|
48
|
-
or real-life usage, this should use your own data store.
|
77
|
+
## Contributing
|
49
78
|
|
50
|
-
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cracklingwit/cw_card_utils.
|
@@ -90,7 +90,7 @@ module CwCardUtils
|
|
90
90
|
|
91
91
|
def extract_synergy_pairs(deck)
|
92
92
|
synergy_cards = deck.main.select do |card|
|
93
|
-
|
93
|
+
card.tags.intersect?([:synergistic_finisher, :tribal_synergy, :scaling_threat])
|
94
94
|
end
|
95
95
|
return [] if synergy_cards.size < 2
|
96
96
|
synergy_cards.map(&:name).combination(2).to_a
|
@@ -4,11 +4,11 @@ module CwCardUtils
|
|
4
4
|
module DecklistParser
|
5
5
|
# A Card is a single card in a deck.
|
6
6
|
class Card
|
7
|
-
def initialize(name, count, cmc_data_source =
|
7
|
+
def initialize(name, count, cmc_data_source = nil)
|
8
8
|
@name = name
|
9
9
|
@count = count
|
10
10
|
@tags = []
|
11
|
-
@cmc_data_source = cmc_data_source
|
11
|
+
@cmc_data_source = cmc_data_source || CwCardUtils.card_data_source
|
12
12
|
end
|
13
13
|
|
14
14
|
attr_reader :name, :count, :cmc_data_source
|
@@ -6,9 +6,9 @@ module CwCardUtils
|
|
6
6
|
class Parser
|
7
7
|
attr_reader :deck
|
8
8
|
|
9
|
-
def initialize(decklist, cmc_data_source =
|
9
|
+
def initialize(decklist, cmc_data_source = nil)
|
10
10
|
@decklist = decklist.is_a?(IO) ? decklist.read : decklist
|
11
|
-
@deck = Deck.new(cmc_data_source)
|
11
|
+
@deck = Deck.new(cmc_data_source || CwCardUtils.card_data_source)
|
12
12
|
end
|
13
13
|
|
14
14
|
def inspect
|
@@ -79,9 +79,9 @@ module CwCardUtils
|
|
79
79
|
|
80
80
|
# Represents a card with Scryfall data
|
81
81
|
class ScryfallCard
|
82
|
-
def initialize(name, data_source =
|
82
|
+
def initialize(name, data_source = nil)
|
83
83
|
@name = name
|
84
|
-
@data = data_source.find_card(@name) || {}
|
84
|
+
@data = (data_source || CwCardUtils.card_data_source).find_card(@name) || {}
|
85
85
|
end
|
86
86
|
|
87
87
|
def cmc
|
data/lib/cw_card_utils.rb
CHANGED
@@ -9,4 +9,17 @@ require_relative "cw_card_utils/deck_comparator"
|
|
9
9
|
|
10
10
|
module CwCardUtils
|
11
11
|
class Error < StandardError; end
|
12
|
+
|
13
|
+
# Configuration for the library
|
14
|
+
class << self
|
15
|
+
attr_writer :card_data_source
|
16
|
+
|
17
|
+
def card_data_source
|
18
|
+
@card_data_source ||= ScryfallCmcData.instance
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield self if block_given?
|
23
|
+
end
|
24
|
+
end
|
12
25
|
end
|