class Tamiyo::CockatriceDbSink

Public Instance Methods

add_cards_to(xml) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/tamiyo/cockatrice_db_sink.rb, line 58
def first_cost_of(card)
  [*card.cost].first
end
pump() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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