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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33af01174c18c349d5ecadd729ff82f228645e4d7de70345e031483a9b6e4aeb
4
- data.tar.gz: d95e60dcf30519bdeca9ca86ab04c727e2b76c1a6de990417bd21bbe41e7ad26
3
+ metadata.gz: 0aab3de52c635cd3e24f8ba808777bfc5e60cb07b0e2f02357c67f00212dcfc9
4
+ data.tar.gz: 28d0d647d3c6f91a69b6853abcd73605e9f116a8251afff8c5f39a7cf77b22fe
5
5
  SHA512:
6
- metadata.gz: dfa2f46a027dda4ffd67bdace956049c47bdc3a009a70f36ade4c722939d38658d05bf8adf57d85753442e44a71f6aeb12a247579277e1ecd38ce17de846bd9e
7
- data.tar.gz: b0e79425dc4ce0d47788cba711c19e80554cf1a89eb63b695cbb03fa2ba0286b2e451cc20364a3b3344fd97cb0f5a56db16ba3464e90a341563fcf58ec245b1d
6
+ metadata.gz: 42be3567474156c9c6417d0c7994485567608af868a3f8dadd832b964c99216397bda74d89e83210c3e170ba1b5d4dddef19c401efc70eb7380dfe8068753c7b
7
+ data.tar.gz: 4218005f3d49d44613e738b2f718f5f1997a314ec81918d865f9bec17b714b6c811f9dfcc2fd6a79ced057175fa8bfc69e15e8f3d0b981b4b7c00d52cb3014af
data/README.md CHANGED
@@ -1,50 +1,79 @@
1
1
  # CwCardUtils
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cw_card_utils'
11
+ ```
10
12
 
11
- Install the gem and add to the application's Gemfile by executing:
13
+ And then execute:
12
14
 
13
15
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ bundle install
15
17
  ```
16
18
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
19
+ ## Configuration
18
20
 
19
- ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
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
- TODO: Write usage instructions here
37
+ ### Basic Deck Parsing
26
38
 
27
- ## Development
39
+ ```ruby
40
+ require 'cw_card_utils'
28
41
 
29
- 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.
42
+ # Parse a decklist
43
+ decklist = <<~DECK
44
+ 4 Lightning Bolt
45
+ 4 Mountain
46
+ 2 Shock
47
+ DECK
30
48
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+ deck = CwCardUtils::DecklistParser::Parser.new(decklist).parse
32
50
 
33
- ## Contributing
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cw_card_utils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/cw_card_utils/blob/main/CODE_OF_CONDUCT.md).
57
+ ### Custom Data Sources
36
58
 
37
- ## License
59
+ You can implement your own card data source by inheriting from `CwCardUtils::CardDataSource`:
38
60
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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
- ## Code of Conduct
69
+ # Configure the library to use your data source
70
+ CwCardUtils.card_data_source = MyCustomDataSource.new
71
+ ```
42
72
 
43
- Everyone interacting in the CwCardUtils project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cw_card_utils/blob/main/CODE_OF_CONDUCT.md).
73
+ ## Development
44
74
 
45
- ## Included Data
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
- This gem includes [bulk data from Scryfall][1] to provide fallback for the curve calculator. For production
48
- or real-life usage, this should use your own data store.
77
+ ## Contributing
49
78
 
50
- [1]: https://scryfall.com/docs/api/bulk-data
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
- (card.tags & [:synergistic_finisher, :tribal_synergy, :scaling_threat]).any?
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 = CwCardUtils::ScryfallCmcData.instance)
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 = CwCardUtils::ScryfallCmcData.instance)
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 = ScryfallCmcData.instance)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CwCardUtils
4
- VERSION = "0.1.9"
4
+ VERSION = "0.1.10"
5
5
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cw_card_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stenhouse