Class: Tamiyo::CockatriceDbSink
- Inherits:
-
Object
- Object
- Tamiyo::CockatriceDbSink
- Includes:
- Process::Node
- Defined in:
- lib/tamiyo/cockatrice_db_sink.rb
Instance Method Summary collapse
- #add_cards_to(xml) ⇒ Object
- #add_sets_to(xml) ⇒ Object
- #adjusted_text_of(card) ⇒ Object
- #first_cost_of(card) ⇒ Object
- #pump ⇒ Object
- #row_of(card) ⇒ Object
- #store_xml(content) ⇒ Object
Methods included from Process::Node
Instance Method Details
#add_cards_to(xml) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tamiyo/cockatrice_db_sink.rb', line 31 def add_cards_to(xml) xml.cards { @chain.pull.each do |card| xml.card { xml.name card.name # sets card.colors.each { |color| xml.color color } xml.manacost first_cost_of card xml.type_ card.type xml.pt card.pt if card.pt xml.loyalty card.loyalty if card.loyalty xml.tablerow row_of card xml.text_ adjusted_text_of card xml.cipt '1' if card.played_tapped } end } end |
#add_sets_to(xml) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tamiyo/cockatrice_db_sink.rb', line 20 def add_sets_to(xml) xml.sets { DefaultData.sets['sets'].each do |abbr, name| xml.set { xml.name abbr xml.longname name } end } end |
#adjusted_text_of(card) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/tamiyo/cockatrice_db_sink.rb', line 71 def adjusted_text_of(card) text = card.text if card.cost.is_a? Array first, second = card.cost text = "Mana cost: #{first}\n#{text}" text.sub!(/---\n/) { |m| m << "Mana cost: #{second}\n" } end text end |
#first_cost_of(card) ⇒ Object
58 59 60 |
# File 'lib/tamiyo/cockatrice_db_sink.rb', line 58 def first_cost_of(card) [*card.cost].first end |
#pump ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/tamiyo/cockatrice_db_sink.rb', line 10 def pump content = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.cockatrice_carddatabase(version: '2') { add_sets_to xml add_cards_to xml } end store_xml content end |
#row_of(card) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/tamiyo/cockatrice_db_sink.rb', line 62 def row_of(card) case card.table_row when :first; '0' when :second; '1' when :third; '2' when :stack; '3' end end |
#store_xml(content) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/tamiyo/cockatrice_db_sink.rb', line 50 def store_xml(content) data_store = DataStore.new path = data_store.path_for 'cards.xml' File.open(path, 'w') do |file| file.write content.to_xml end end |