cw_card_utils 0.1.0 → 0.1.1
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/lib/cw_card_utils/curve_calculator.rb +42 -3
- data/lib/cw_card_utils/decklist_parser.rb +30 -6
- data/lib/cw_card_utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e84c44da534cca5805a700be0bb4d6879e79331cd7661ebd26ade34ccdd21f6d
|
4
|
+
data.tar.gz: 2dbd8e194dc74cba381cfebd85563bf40e8b924be63f5da20c8afbd73d3372ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24c78700494fb3127867abda79718387c2563c4c4cc1f4c80fded769f14a198074fd86aadb43b24474c352b9f40a249b8434126cc6c27f03987b08b84edd08fb
|
7
|
+
data.tar.gz: 54bfabb464f898fe874310dfbabcfb18d47f64911a85e4db0f85bcc4b69eb7be8a9ab798b61871f43b1311af4bf344f3ae9863308043afa5214316c081f11db4
|
@@ -4,9 +4,37 @@ module CwCardUtils
|
|
4
4
|
class CurveCalculator
|
5
5
|
def initialize(deck)
|
6
6
|
@deck = deck
|
7
|
-
@deck_size = deck.
|
7
|
+
@deck_size = @deck.count_without_lands
|
8
8
|
@raw_curve = {}
|
9
9
|
@normalized_curve = {}
|
10
|
+
@collapsed_normalized_curve = {}
|
11
|
+
@collapsed_curve = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def collapsed_curve
|
15
|
+
return @collapsed_curve if @collapsed_curve.values.any?
|
16
|
+
|
17
|
+
@collapsed_curve = {
|
18
|
+
'0-1' => 0,
|
19
|
+
'2' => 0,
|
20
|
+
'3' => 0,
|
21
|
+
'4' => 0,
|
22
|
+
'5' => 0,
|
23
|
+
'6+' => 0
|
24
|
+
}
|
25
|
+
|
26
|
+
curve.each do |cmc, count|
|
27
|
+
case cmc
|
28
|
+
when 0..1 then @collapsed_curve['0-1'] += count
|
29
|
+
when 2 then @collapsed_curve['2'] += count
|
30
|
+
when 3 then @collapsed_curve['3'] += count
|
31
|
+
when 4 then @collapsed_curve['4'] += count
|
32
|
+
when 5 then @collapsed_curve['5'] += count
|
33
|
+
else @collapsed_curve['6+'] += count
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
@collapsed_curve
|
10
38
|
end
|
11
39
|
|
12
40
|
def curve
|
@@ -15,10 +43,15 @@ module CwCardUtils
|
|
15
43
|
end
|
16
44
|
|
17
45
|
def normalized_curve
|
18
|
-
normalize_curve if @normalized_curve.empty?
|
46
|
+
normalize_curve if @normalized_curve.values.empty?
|
19
47
|
@normalized_curve
|
20
48
|
end
|
21
49
|
|
50
|
+
def collapsed_normalized_curve
|
51
|
+
normalize_collapsed_curve if @collapsed_normalized_curve.values.empty?
|
52
|
+
@collapsed_normalized_curve
|
53
|
+
end
|
54
|
+
|
22
55
|
private
|
23
56
|
|
24
57
|
def calculate_curve
|
@@ -44,7 +77,13 @@ module CwCardUtils
|
|
44
77
|
|
45
78
|
def normalize_curve
|
46
79
|
@normalized_curve = curve.sort_by { |cmc, _| cmc }.to_h.transform_values do |count|
|
47
|
-
(count / @
|
80
|
+
(count / @deck.count_without_lands.to_f).round(4)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def normalize_collapsed_curve
|
85
|
+
@collapsed_normalized_curve =collapsed_curve.sort_by { |cmc, _| cmc }.to_h.transform_values do |count|
|
86
|
+
(count / @deck.count_without_lands.to_f).round(4)
|
48
87
|
end
|
49
88
|
end
|
50
89
|
end
|
@@ -82,13 +82,16 @@ module CwCardUtils
|
|
82
82
|
def initialize(cmc_data_source)
|
83
83
|
@main = []
|
84
84
|
@sideboard = []
|
85
|
+
@lands = []
|
86
|
+
@x_to_cast = []
|
87
|
+
|
85
88
|
@cmc_data_source = cmc_data_source
|
86
89
|
end
|
87
90
|
|
88
91
|
def to_h
|
89
92
|
{
|
90
|
-
mainboard: @main.map
|
91
|
-
sideboard: @sideboard.map
|
93
|
+
mainboard: @main.map(&:to_h),
|
94
|
+
sideboard: @sideboard.map(&:to_h),
|
92
95
|
}
|
93
96
|
end
|
94
97
|
|
@@ -110,40 +113,61 @@ module CwCardUtils
|
|
110
113
|
|
111
114
|
def each(&block)
|
112
115
|
@main.each do |c|
|
113
|
-
c = Card.new(c[:name], c[:count], @cmc_data_source)
|
114
116
|
block.call(c)
|
115
117
|
end
|
116
118
|
end
|
117
119
|
|
118
120
|
attr_reader :main, :sideboard
|
119
121
|
|
120
|
-
def add(
|
122
|
+
def add(c, target = :mainboard)
|
121
123
|
reset_counters
|
124
|
+
card = Card.new(c[:name], c[:count], @cmc_data_source)
|
125
|
+
|
122
126
|
if target == :mainboard
|
123
127
|
@main << card
|
124
128
|
else
|
125
129
|
@sideboard << card
|
126
130
|
end
|
131
|
+
|
132
|
+
if card.type == "Land"
|
133
|
+
@lands << card
|
134
|
+
elsif card.cmc.nil?
|
135
|
+
@x_to_cast << card
|
136
|
+
end
|
127
137
|
end
|
128
138
|
|
129
139
|
def reset_counters
|
130
140
|
@mainboard_size = nil
|
131
141
|
@sideboard_size = nil
|
142
|
+
@lands_count = nil
|
143
|
+
@x_to_cast_count = nil
|
132
144
|
@cards_count = nil
|
133
145
|
end
|
134
146
|
|
135
147
|
def mainboard_size
|
136
|
-
@mainboard_size ||= main.sum { |card| card
|
148
|
+
@mainboard_size ||= main.sum { |card| card.count }
|
137
149
|
end
|
138
150
|
|
139
151
|
def sideboard_size
|
140
|
-
@sideboard_size ||= sideboard.sum { |card| card
|
152
|
+
@sideboard_size ||= sideboard.sum { |card| card.count }
|
153
|
+
end
|
154
|
+
|
155
|
+
def lands_count
|
156
|
+
@lands_count ||= @lands.sum { |card| card.count }
|
157
|
+
end
|
158
|
+
|
159
|
+
def x_to_cast_count
|
160
|
+
@x_to_cast_count ||= @x_to_cast.sum { |card| card.count }
|
141
161
|
end
|
142
162
|
|
143
163
|
def cards_count
|
144
164
|
@cards_count ||= mainboard_size + sideboard_size
|
145
165
|
end
|
146
166
|
|
167
|
+
def count_without_lands
|
168
|
+
@count_without_lands ||= cards_count - lands_count
|
169
|
+
end
|
170
|
+
|
147
171
|
def size
|
148
172
|
cards_count
|
149
173
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cw_card_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stenhouse
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-07-
|
10
|
+
date: 2025-07-27 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: json
|