mtg_search_parser 0.0.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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +125 -0
  7. data/Rakefile +1 -0
  8. data/lib/mtg_search_parser.rb +92 -0
  9. data/lib/mtg_search_parser/lexer.rb +80 -0
  10. data/lib/mtg_search_parser/nodes/and.rb +6 -0
  11. data/lib/mtg_search_parser/nodes/left_paren.rb +6 -0
  12. data/lib/mtg_search_parser/nodes/node.rb +13 -0
  13. data/lib/mtg_search_parser/nodes/not.rb +6 -0
  14. data/lib/mtg_search_parser/nodes/or.rb +6 -0
  15. data/lib/mtg_search_parser/nodes/query.rb +19 -0
  16. data/lib/mtg_search_parser/nodes/right_paren.rb +6 -0
  17. data/lib/mtg_search_parser/not_group.rb +13 -0
  18. data/lib/mtg_search_parser/or_group.rb +13 -0
  19. data/lib/mtg_search_parser/parsed/any_color.rb +7 -0
  20. data/lib/mtg_search_parser/parsed/artist.rb +7 -0
  21. data/lib/mtg_search_parser/parsed/banned.rb +7 -0
  22. data/lib/mtg_search_parser/parsed/base.rb +15 -0
  23. data/lib/mtg_search_parser/parsed/card_type.rb +7 -0
  24. data/lib/mtg_search_parser/parsed/color_identity.rb +7 -0
  25. data/lib/mtg_search_parser/parsed/edition.rb +7 -0
  26. data/lib/mtg_search_parser/parsed/exact_color.rb +7 -0
  27. data/lib/mtg_search_parser/parsed/exact_name.rb +7 -0
  28. data/lib/mtg_search_parser/parsed/language.rb +7 -0
  29. data/lib/mtg_search_parser/parsed/legal.rb +7 -0
  30. data/lib/mtg_search_parser/parsed/mana_cost.rb +18 -0
  31. data/lib/mtg_search_parser/parsed/name.rb +7 -0
  32. data/lib/mtg_search_parser/parsed/power_tough_compare.rb +20 -0
  33. data/lib/mtg_search_parser/parsed/quality.rb +7 -0
  34. data/lib/mtg_search_parser/parsed/rarity.rb +7 -0
  35. data/lib/mtg_search_parser/parsed/release_year.rb +18 -0
  36. data/lib/mtg_search_parser/parsed/rules_text.rb +7 -0
  37. data/lib/mtg_search_parser/parser.rb +60 -0
  38. data/lib/mtg_search_parser/version.rb +3 -0
  39. data/mtg_search_parser.gemspec +23 -0
  40. data/spec/lexer_spec.rb +94 -0
  41. data/spec/mtg_search_parser_spec.rb +62 -0
  42. data/spec/parser_spec.rb +256 -0
  43. data/spec/spec_helper.rb +80 -0
  44. metadata +132 -0
@@ -0,0 +1,256 @@
1
+ require 'spec_helper'
2
+
3
+ module MtgSearchParser
4
+ describe Parser do
5
+ describe "#parse" do
6
+ context "name" do
7
+ it "Birds of Paradise" do
8
+ expect(subject.parse("Birds of Paradise")).
9
+ to eq(Parsed::Name.new("Birds of Paradise"))
10
+ end
11
+
12
+ it '"Birds of Paradise"' do
13
+ expect(subject.parse('"Birds of Paradise"')).
14
+ to eq(Parsed::Name.new("Birds of Paradise"))
15
+ end
16
+
17
+ it "!Birds of Paradise" do
18
+ expect(subject.parse("!Birds of Paradise")).
19
+ to eq(Parsed::ExactName.new("Birds of Paradise"))
20
+ end
21
+ end
22
+
23
+ context "rules text" do
24
+ it "o:Flying" do
25
+ expect(subject.parse("o:Flying")).
26
+ to eq(Parsed::RulesText.new("Flying"))
27
+ end
28
+
29
+ it 'o:"First strike"' do
30
+ expect(subject.parse('o:"First strike"')).
31
+ to eq(Parsed::RulesText.new("First strike"))
32
+ end
33
+
34
+ it 'o:"add one mana of any color"' do
35
+ expect(subject.parse('o:"add one mana of any color"')).
36
+ to eq(Parsed::RulesText.new("add one mana of any color"))
37
+ end
38
+
39
+ it 'o:{T}' do
40
+ expect(subject.parse('o:{T}')).
41
+ to eq(Parsed::RulesText.new("{T}"))
42
+ end
43
+
44
+ it 'o:"whenever ~ deals combat damage"' do
45
+ expect(subject.parse('o:"whenever ~ deals combat damage"')).
46
+ to eq(Parsed::RulesText.new("whenever ~ deals combat damage"))
47
+ end
48
+ end
49
+
50
+ context "types" do
51
+ it 't:angel' do
52
+ expect(subject.parse('t:angel')).
53
+ to eq(Parsed::CardType.new("angel"))
54
+ end
55
+
56
+ it 't:"legendary angel"' do
57
+ expect(subject.parse('t:"legendary angel"')).
58
+ to eq(Parsed::CardType.new("legendary angel"))
59
+ end
60
+
61
+ it 't:basic' do
62
+ expect(subject.parse('t:basic')).
63
+ to eq(Parsed::CardType.new("basic"))
64
+ end
65
+
66
+ it 't:"arcane instant"' do
67
+ expect(subject.parse('t:"arcane instant"')).
68
+ to eq(Parsed::CardType.new("arcane instant"))
69
+ end
70
+ end
71
+
72
+ context "colors" do
73
+ it 'c:w (Any card that is white)' do
74
+ expect(subject.parse('c:w')).
75
+ to eq(Parsed::AnyColor.new("w"))
76
+ end
77
+
78
+ it 'c:wu (Any card that is white or blue)' do
79
+ expect(subject.parse('c:wu')).
80
+ to eq(Parsed::AnyColor.new("wu"))
81
+ end
82
+
83
+ it 'c:wum (Any card that is white or blue, and multicolored)' do
84
+ expect(subject.parse('c:wum')).
85
+ to eq(Parsed::AnyColor.new("wum"))
86
+ end
87
+
88
+ it 'c!w (Cards that are only white)' do
89
+ expect(subject.parse('c!w')).
90
+ to eq(Parsed::ExactColor.new("w"))
91
+ end
92
+
93
+ it 'c!wu (Cards that are only white or blue, or both)' do
94
+ expect(subject.parse('c!wu')).
95
+ to eq(Parsed::ExactColor.new("wu"))
96
+ end
97
+
98
+ it 'c!wum (Cards that are only white and blue, and multicolored)' do
99
+ expect(subject.parse('c!wum')).
100
+ to eq(Parsed::ExactColor.new("wum"))
101
+ end
102
+
103
+ it 'c!wubrgm (Cards that are all five colors)' do
104
+ expect(subject.parse('c!wubrgm')).
105
+ to eq(Parsed::ExactColor.new("wubrgm"))
106
+ end
107
+
108
+ it 'c:m (Any multicolored card)' do
109
+ expect(subject.parse('c:m')).
110
+ to eq(Parsed::AnyColor.new("m"))
111
+ end
112
+
113
+ it 'c:l (Land cards)' do
114
+ expect(subject.parse('c:l')).
115
+ to eq(Parsed::AnyColor.new("l"))
116
+ end
117
+
118
+ it 'c:c (colorless cards)' do
119
+ expect(subject.parse('c:c')).
120
+ to eq(Parsed::AnyColor.new("c"))
121
+ end
122
+ end
123
+
124
+ context "color identity" do
125
+ it 'ci:wu (Any card that is white or blue, but does not contain any black, red or green mana symbols)' do
126
+ expect(subject.parse('ci:wu')).
127
+ to eq(Parsed::ColorIdentity.new("wu"))
128
+ end
129
+ end
130
+
131
+ context "mana cost" do
132
+ it 'mana=3G (Spells that cost exactly 3G, or split cards that can be cast with 3G)' do
133
+ expect(subject.parse('mana=3G')).
134
+ to eq(Parsed::ManaCost.new("=", "3G"))
135
+ end
136
+
137
+ it 'mana>=2WW (Spells that cost at least two white and two colorless mana)' do
138
+ expect(subject.parse('mana>=2WW')).
139
+ to eq(Parsed::ManaCost.new(">=", "2WW"))
140
+ end
141
+
142
+ it 'mana<GGGGGG (Spells that can be cast with strictly less than six green mana)' do
143
+ expect(subject.parse('mana<GGGGGG')).
144
+ to eq(Parsed::ManaCost.new("<", "GGGGGG"))
145
+ end
146
+
147
+ it 'mana>={2/R}' do
148
+ expect(subject.parse('mana>={2/R}')).
149
+ to eq(Parsed::ManaCost.new(">=", "{2/R}"))
150
+ end
151
+
152
+ it 'mana>={W/U}' do
153
+ expect(subject.parse('mana>={W/U}')).
154
+ to eq(Parsed::ManaCost.new(">=", "{W/U}"))
155
+ end
156
+
157
+ it 'mana>={UP}' do
158
+ expect(subject.parse('mana>={UP}')).
159
+ to eq(Parsed::ManaCost.new(">=", "{UP}"))
160
+ end
161
+ end
162
+
163
+ context "Power, Toughness, Converted Mana Cost" do
164
+ it 'pow>=8' do
165
+ expect(subject.parse('pow>=8')).
166
+ to eq(Parsed::PowerToughCompare.new("pow", ">=", "8"))
167
+ end
168
+
169
+ it 'tou<pow (All combinations are possible)' do
170
+ expect(subject.parse('tou<pow')).
171
+ to eq(Parsed::PowerToughCompare.new("tou", "<", "pow"))
172
+ end
173
+
174
+ it 'pow>cmc (All combinations are possible)' do
175
+ expect(subject.parse('pow>cmc')).
176
+ to eq(Parsed::PowerToughCompare.new("pow", ">", "cmc"))
177
+ end
178
+
179
+ it 'cmc=7' do
180
+ expect(subject.parse('cmc=7')).
181
+ to eq(Parsed::PowerToughCompare.new("cmc", "=", "7"))
182
+ end
183
+
184
+ it 'cmc>=*' do
185
+ expect(subject.parse('cmc>=*')).
186
+ to eq(Parsed::PowerToughCompare.new("cmc", ">=", "*"))
187
+ end
188
+ end
189
+
190
+ context "Rarity" do
191
+ it 'r:mythic' do
192
+ expect(subject.parse('r:mythic')).
193
+ to eq(Parsed::Rarity.new("mythic"))
194
+ end
195
+ end
196
+
197
+ context 'Format' do
198
+ it 'f:standard (or block, extended, vintage, classic, legacy, modern, commander)' do
199
+ expect(subject.parse('f:standard')).
200
+ to eq(Parsed::Legal.new("standard"))
201
+ end
202
+
203
+ it 'banned:extended (or legal, restricted)' do
204
+ expect(subject.parse('banned:extended')).
205
+ to eq(Parsed::Banned.new("extended"))
206
+ end
207
+ end
208
+
209
+ context "Artist" do
210
+ it 'a:"rk post"' do
211
+ expect(subject.parse('a:"rk post"')).
212
+ to eq(Parsed::Artist.new("rk post"))
213
+ end
214
+ end
215
+
216
+ context "Edition" do
217
+ it 'e:al (Uses the abbreviations that are listed on the sitemap)' do
218
+ expect(subject.parse('e:al')).
219
+ to eq(Parsed::Edition.new("al"))
220
+ end
221
+
222
+ it 'e:al,be (Cards that appear in Alpha or Beta)' do
223
+ expect(subject.parse('e:al,be')).
224
+ to eq(Parsed::Edition.new("al,be"))
225
+ end
226
+
227
+ it 'e:al+be (Cards that appear in Alpha and Beta)' do
228
+ expect(subject.parse('e:al+be')).
229
+ to eq(Parsed::Edition.new("al+be"))
230
+ end
231
+
232
+ it 'year<=1995 (Cards printed in 1995 and earlier)' do
233
+ expect(subject.parse('year<=1995')).
234
+ to eq(Parsed::ReleaseYear.new("<=", "1995"))
235
+ end
236
+ end
237
+
238
+ context "Is:" do
239
+ %w[split vanilla old new future timeshifted funny promo permanent
240
+ spell black-bordered white-bordered sliver-bordered foil].each do |quality|
241
+ it "is:#{quality}" do
242
+ expect(subject.parse("is:#{quality}")).
243
+ to eq(Parsed::Quality.new(quality))
244
+ end
245
+ end
246
+ end
247
+
248
+ context "Language" do
249
+ it 'l:de, l:it, l:jp (Uses the abbreviations that are listed on the sitemap)' do
250
+ expect(subject.parse('l:de')).
251
+ to eq(Parsed::Language.new("de"))
252
+ end
253
+ end
254
+ end
255
+ end
256
+ end
@@ -0,0 +1,80 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
79
+
80
+ require './lib/mtg_search_parser'
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mtg_search_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Donald Plummer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - donald.plummer@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/mtg_search_parser.rb
69
+ - lib/mtg_search_parser/lexer.rb
70
+ - lib/mtg_search_parser/nodes/and.rb
71
+ - lib/mtg_search_parser/nodes/left_paren.rb
72
+ - lib/mtg_search_parser/nodes/node.rb
73
+ - lib/mtg_search_parser/nodes/not.rb
74
+ - lib/mtg_search_parser/nodes/or.rb
75
+ - lib/mtg_search_parser/nodes/query.rb
76
+ - lib/mtg_search_parser/nodes/right_paren.rb
77
+ - lib/mtg_search_parser/not_group.rb
78
+ - lib/mtg_search_parser/or_group.rb
79
+ - lib/mtg_search_parser/parsed/any_color.rb
80
+ - lib/mtg_search_parser/parsed/artist.rb
81
+ - lib/mtg_search_parser/parsed/banned.rb
82
+ - lib/mtg_search_parser/parsed/base.rb
83
+ - lib/mtg_search_parser/parsed/card_type.rb
84
+ - lib/mtg_search_parser/parsed/color_identity.rb
85
+ - lib/mtg_search_parser/parsed/edition.rb
86
+ - lib/mtg_search_parser/parsed/exact_color.rb
87
+ - lib/mtg_search_parser/parsed/exact_name.rb
88
+ - lib/mtg_search_parser/parsed/language.rb
89
+ - lib/mtg_search_parser/parsed/legal.rb
90
+ - lib/mtg_search_parser/parsed/mana_cost.rb
91
+ - lib/mtg_search_parser/parsed/name.rb
92
+ - lib/mtg_search_parser/parsed/power_tough_compare.rb
93
+ - lib/mtg_search_parser/parsed/quality.rb
94
+ - lib/mtg_search_parser/parsed/rarity.rb
95
+ - lib/mtg_search_parser/parsed/release_year.rb
96
+ - lib/mtg_search_parser/parsed/rules_text.rb
97
+ - lib/mtg_search_parser/parser.rb
98
+ - lib/mtg_search_parser/version.rb
99
+ - mtg_search_parser.gemspec
100
+ - spec/lexer_spec.rb
101
+ - spec/mtg_search_parser_spec.rb
102
+ - spec/parser_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/dplummer/mtg_search_parser
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A ruby implementation of a MTG search string parser.
128
+ test_files:
129
+ - spec/lexer_spec.rb
130
+ - spec/mtg_search_parser_spec.rb
131
+ - spec/parser_spec.rb
132
+ - spec/spec_helper.rb