Module: Card::Set::All::Chunk::Format

Extended by:
Card::Set::AbstractFormat
Defined in:
tmpsets/set/mod003-core/all/chunk.rb

Instance Method Summary collapse

Instance Method Details

#each_nested_card(content = nil, fields_only = false, &block) ⇒ Object



93
94
95
96
97
98
99
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 93

def each_nested_card content=nil, fields_only=false, &block
  processed = process_tally
  nest_chunks(content).each do |chunk|
    next if fields_only && !field_chunk?(chunk)
    process_nested_chunk chunk, processed, &block
  end
end

#each_nested_field(content = nil, &block) ⇒ Object



89
90
91
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 89

def each_nested_field content=nil, &block
  each_nested_card content, true, &block
end

#edit_fieldsObject



61
62
63
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 61

def edit_fields
  voo.edit_structure || []
end

#field_chunk?(chunk) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 118

def field_chunk? chunk
  chunk.referee_name.to_name.field_of? card.name
end

#nest_chunks(content = nil) ⇒ Object



109
110
111
112
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 109

def nest_chunks content=nil
  content ||= _render_raw
  card.nest_chunks content
end

#nested_cards_for_edit(fields_only = false) ⇒ Object



52
53
54
55
56
57
58
59
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 52

def nested_cards_for_edit fields_only=false
  return normalized_edit_fields if edit_fields.present?
  result = []
  each_nested_card nil, fields_only do |chunk|
    result << [chunk.options[:nest_name], chunk.options]
  end
  result
end

#nested_field_cards(content = nil) ⇒ Object



46
47
48
49
50
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 46

def nested_field_cards content=nil
  nested_fields(content).map do |name, _options|
    Card.fetch name
  end
end

#nested_fields(content = nil) ⇒ Object



38
39
40
41
42
43
44
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 38

def nested_fields content=nil
  result = []
  each_nested_card(content, true) do |chunk|
    result << [chunk.referee_name, chunk.options]
  end
  result
end

#normalized_edit_field_mark(cardish, options) ⇒ Object



78
79
80
81
82
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 78

def normalized_edit_field_mark cardish, options
  return cardish if cardish.is_a?(Card) ||
                    (options.is_a?(Hash) && options.delete(:absolute))
  card.name.field cardish
end

#normalized_edit_field_options(options, cardname) ⇒ Object



73
74
75
76
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 73

def normalized_edit_field_options options, cardname
  options ||= cardname
  options.is_a?(String) ? { title: options } : options
end

#normalized_edit_fieldsObject



65
66
67
68
69
70
71
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 65

def normalized_edit_fields
  edit_fields.map do |cardish, options|
    field_mark = normalized_edit_field_mark cardish, options
    options = normalized_edit_field_options options, Card::Name[field_mark]
    [field_mark, options]
  end
end

#process_field(chunk, processed) {|chunk| ... } ⇒ Object

Yields:

  • (chunk)


84
85
86
87
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 84

def process_field chunk, processed
  return unless process_unique_field? chunk, processed
  yield chunk if block_given?
end

#process_nested_chunk(chunk, processed, &block) ⇒ Object



134
135
136
137
138
139
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 134

def process_nested_chunk chunk, processed, &block
  virtual = chunk.referee_card&.virtual?
  # TODO: handle structures that are non-virtual
  method = virtual ? :process_virtual_field : :process_field
  send method, chunk, processed, &block
end

#process_tallyObject



114
115
116
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 114

def process_tally
  ::Set.new [card.key]
end

#process_unique_field?(chunk, processed) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
151
152
153
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 148

def process_unique_field? chunk, processed
  key = chunk.referee_name.key
  return false if processed.include? key
  processed << key
  true
end

#process_virtual_field(chunk, processed, &block) ⇒ Object



141
142
143
144
145
146
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 141

def process_virtual_field chunk, processed, &block
  return unless process_unique_field? chunk, processed
  subformat(chunk.referee_card).each_nested_field do |sub_chunk|
    process_field sub_chunk, processed, &block
  end
end

#uniq_nested_cards(content: nil) ⇒ Object



101
102
103
104
105
106
107
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 101

def uniq_nested_cards content: nil
  with_unique_chunks do
    nest_chunks(content).map do |chunk|
      chunk.referee_card if unique_chunk? chunk
    end
  end
end

#unique_chunk?(chunk) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
125
126
127
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 122

def unique_chunk? chunk
  key = chunk.referee_name.key
  return false if @processed.include? key
  @processed << key
  true
end

#with_unique_chunksObject



129
130
131
132
# File 'tmpsets/set/mod003-core/all/chunk.rb', line 129

def with_unique_chunks
  @processed = ::Set.new [card.key]
  yield
end