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

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod007-card-mod-content/all/chunk.rb,
card/tmpsets/set/mod006-card-mod-content/all/chunk.rb

Instance Method Summary collapse

Instance Method Details

#each_nested_chunk(content: nil, fields: false, uniq: true, virtual: true, &block) ⇒ Object



84
85
86
87
88
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 84

def each_nested_chunk content: nil, fields: false, uniq: true, virtual: true, &block
  return unless block_given?
  chunks = prepare_nested_chunks content, fields, uniq
  process_nested_chunks chunks, virtual, &block
end

#each_nested_field_chunk(&block) ⇒ Object



80
81
82
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 80

def each_nested_field_chunk &block
  each_nested_chunk fields: true, &block
end

#edit_field_configs(fields_only = false) ⇒ Array

Returns of Arrays. each is [nest_name, nest_options_hash].

Returns:

  • (Array)

    of Arrays. each is [nest_name, nest_options_hash]



64
65
66
67
68
69
70
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 64

def edit_field_configs fields_only=false
  if edit_fields.present?
    explicit_edit_fields_config # explicitly configured in voo or code
  else
    implicit_edit_fields_config fields_only # inferred from nests
  end
end

#edit_fieldsObject



47
48
49
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 47

def edit_fields
  voo.edit_structure || []
end

#field_chunks(chunks) ⇒ Object



100
101
102
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 100

def field_chunks chunks
  chunks.select { |chunk| field_name?(chunk.referee_name) }
end

#field_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 59

def field_name? name
  name.field_of? card.name
end

#implicit_edit_fields_config(fields_only) ⇒ Object



72
73
74
75
76
77
78
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 72

def implicit_edit_fields_config fields_only
  result = []
  each_nested_chunk(fields: fields_only) do |chunk|
    result << [chunk.options[:nest_name], chunk.options]
  end
  result
end

#nest_chunks(content = nil) ⇒ Object



38
39
40
41
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 38

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

#nested_cards(content = nil) ⇒ Object



43
44
45
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 43

def nested_cards content=nil
  nest_chunks(content).map(&:referee_card).uniq
end

#nested_field_cards(content = nil) ⇒ Object



55
56
57
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 55

def nested_field_cards content=nil
  nested_cards(content).select { |c| field_name? c.name }
end

#nested_field_names(content = nil) ⇒ Object



51
52
53
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 51

def nested_field_names content=nil
  nest_chunks(content).map(&:referee_name).select { |n| field_name? n }
end

#uniq_chunks(chunks) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'card/tmpsets/set/mod007-card-mod-content/all/chunk.rb', line 90

def uniq_chunks chunks
  processed = ::Set.new [card.key]
  chunks.select do |chunk|
    key = chunk.referee_name.key
    ok = !processed.include?(key)
    processed << key
    ok
  end
end