Class: Tamiyo::CockatriceDbSink
Instance Method Summary
collapse
Methods included from DataStore
#default_set_data, #provide_path_for
#affix
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
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 {
default_set_data['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.respond_to? :each
first, second = card.cost
text = "Mana cost: #{first}\n" << text
text = text.sub!(/---\n/) { |m| m << "Mana cost: #{second}\n" }
end
text
end
|
#first_cost_of(card) ⇒ Object
57
58
59
60
|
# File 'lib/tamiyo/cockatrice_db_sink.rb', line 57
def first_cost_of(card)
cost = card.cost
cost.is_a?(Array) ? cost.first : cost
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
|
# File 'lib/tamiyo/cockatrice_db_sink.rb', line 50
def store_xml(content)
path = provide_path_for 'cards.xml'
File.open(path, 'w') do |file|
file.write content.to_xml
end
end
|