Class: Tamiyo::Yaml::YamlSink

Inherits:
Object
  • Object
show all
Includes:
DataStore, Process::Node, Tamiyo::YamlHelper
Defined in:
lib/tamiyo/yaml/yaml_sink.rb

Instance Method Summary collapse

Methods included from Tamiyo::YamlHelper

#emit_block_mapping, #emit_block_sequence, #emit_end_of_one_document, #emit_flow_sequence, #emit_literal, #emit_pair, #emit_pair_with_literal_value, #emit_pair_with_optional_sequence_value, #emit_pair_with_sequence_value, #emit_plain, #emit_start_of_one_document, #setup_yaml_emitter_for, #yaml_event_stream_for

Methods included from DataStore

#default_set_data, #provide_path_for

Methods included from Process::Node

#affix

Instance Method Details

#pumpObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tamiyo/yaml/yaml_sink.rb', line 12

def pump
  with_the_cards_file do
    emit_block_sequence do
      @chain.pull.each do |card|
        emit_block_mapping do
          emit_pair 'name', card.name
          emit_pair_with_sequence_value 'identity', card.colors unless card.colors.empty?
          emit_pair_with_optional_sequence_value 'mana cost', card.cost
          emit_pair 'type', card.type
          emit_pair_with_literal_value 'text', card.text
          emit_pair 'pt', card.pt if card.pt
          emit_pair 'loyalty', card.loyalty if card.loyalty
          emit_pair 'played tapped', 'true' if card.played_tapped
          emit_pair 'row', card.table_row.to_s
        end
      end
    end
  end
end

#with_the_cards_file(&block) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/tamiyo/yaml/yaml_sink.rb', line 32

def with_the_cards_file(&block)
  file_name = provide_path_for 'cards.yaml'
  if block_given?
    File.open(file_name, 'w') do |file|
      within_a_yaml_document_of file, &block
    end
  end
end

#within_a_yaml_document_of(file) ⇒ Object



41
42
43
44
45
46
# File 'lib/tamiyo/yaml/yaml_sink.rb', line 41

def within_a_yaml_document_of(file)
  setup_yaml_emitter_for file
  emit_start_of_one_document
  yield
  emit_end_of_one_document
end