https://github.com/eirc/spells
Spells is a library for parsing the text on Magic the Gathering cards
https://github.com/eirc/spells
Last synced: about 1 year ago
JSON representation
Spells is a library for parsing the text on Magic the Gathering cards
- Host: GitHub
- URL: https://github.com/eirc/spells
- Owner: eirc
- License: mit
- Created: 2014-04-03T23:18:23.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-04-08T19:55:24.000Z (about 12 years ago)
- Last Synced: 2025-03-27T14:51:57.539Z (over 1 year ago)
- Language: Ruby
- Size: 243 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Spells
[](http://badge.fury.io/rb/spells)
[](https://travis-ci.org/eirc/spells)
[](https://codeclimate.com/github/eirc/spells)
[](https://www.pullreview.com/github/eirc/spells/reviews/master)
[](https://gemnasium.com/eirc/spells)
[](https://coveralls.io/r/eirc/spells)
Spells is a library for parsing the text on Magic: The Gathering cards.
Note that this is pre-pre-Alpha software and you should probably not really use it!
## Installation
Add this line to your application's Gemfile:
gem 'spells'
And then execute:
$ bundle
Or install it yourself as:
$ gem install spells
## Usage
Parsing activated abilities
```ruby
card = Spells::Card.new
card.text = "{2}{R}, {T}: Ghost-Lit Raider deals 2 damage to target creature.
Channel - {3}{R}, Discard Ghost-Lit Raider: Ghost-Lit Raider deals 4 damage to target creature."
card.abilities.map &:text_value
# => ["{2}{R}, {T}: Ghost-Lit Raider deals 2 damage to target creature.", "Channel - {3}{R}, Discard Ghost-Lit Raider: Ghost-Lit Raider deals 4 damage to target creature."]
card.triggered_abilities.map &:text_value
# => []
card.activated_abilities.map &:text_value
# => ["{2}{R}, {T}: Ghost-Lit Raider deals 2 damage to target creature.", "Channel - {3}{R}, Discard Ghost-Lit Raider: Ghost-Lit Raider deals 4 damage to target creature."]
```
Parsing triggered abilities
```ruby
card = Spells::Card.new
card.text = "Whenever Abomination blocks or becomes blocked by a green or white creature, destroy that creature at end of combat."
card.abilities.map &:text_value
# => ["Whenever Abomination blocks or becomes blocked by a green or white creature, destroy that creature at end of combat."]
card.triggered_abilities.map &:text_value
# => ["Whenever Abomination blocks or becomes blocked by a green or white creature, destroy that creature at end of combat."]
card.activated_abilities.map &:text_value
# => []
```
## Development
This gem uses the [treetop](http://treetop.rubyforge.org) gem for declaring the syntax tree. Some resources on treetop:
* http://treetop.rubyforge.org
* http://thingsaaronmade.com/blog/a-quick-intro-to-writing-a-parser-using-treetop.html
## Resources
Other open source or general resources related to Magic: The Gathering
* https://github.com/ancestral/Verse
* https://github.com/Zannick/demystify
* http://www.goblinopera.com/mathemagics
* http://wololo.net/2009/08/12/parsing-cards
* https://code.google.com/p/laterna-magica
## Contributing
1. Fork it ( https://github.com/[my-github-username]/spells/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request