Module: Card::Set::All::Export::JsonFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod008-card-mod-format/all/export.rb,
card/tmpsets/set/mod007-card-mod-format/all/export.rb

Instance Method Summary collapse

Instance Method Details

#export_items_in_view(view) ⇒ Object



35
36
37
38
39
40
41
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 35

def export_items_in_view view
  within_max_depth do
    valid_items_for_export.map do |item|
      nest item, view: view
    end
  end
end

#exporting_uniquesObject



48
49
50
51
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 48

def exporting_uniques
  @exported_keys ||= inherit(:exported_keys) || ::Set.new
  yield
end

#items_for_exportObject



59
60
61
62
63
64
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 59

def items_for_export
  nest_chunks.map do |chunk|
    next if chunk.try :main?
    chunk.referee_card
  end.compact
end

#max_export_depthObject



16
17
18
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 16

def max_export_depth
  Env.params[:max_export_depth].present? ? Env.params[:max_export_depth].to_i : 2
end

#track_exporting(card) ⇒ Object



43
44
45
46
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 43

def track_exporting card
  return unless @exported_keys
  @exported_keys << card.key
end

#valid_export_card?(ecard) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 72

def valid_export_card? ecard
  ecard.real? && !@exported_keys.include?(ecard.key)
end

#valid_items_for_exportObject



66
67
68
69
70
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 66

def valid_items_for_export
  items_for_export.flatten.reject(&:blank?).uniq.find_all do |card|
    valid_export_card? card
  end
end

#view: exportObject

returns an array of Hashes (each in export_item view)



10
11
12
13
14
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 10

view :export, cache: :never do
  exporting_uniques do
    Array.wrap(render_export_item).concat(export_items_in_view(:export)).flatten
  end
end

#view: export_itemObject

returns Hash with the essentials needed to import a card into a new database



28
29
30
31
32
33
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 28

view :export_item do
  item = { name: card.name, type: card.type_name, content: card.content }
  item[:codename] = card.codename if card.codename
  track_exporting card
  item
end

#view: export_itemsObject

returns an array of Hashes (each in export_item view)



21
22
23
24
25
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 21

view :export_items, cache: :never do
  exporting_uniques do
    export_items_in_view(:export).flatten
  end
end

#within_max_depthObject

prevent recursion



54
55
56
57
# File 'card/tmpsets/set/mod008-card-mod-format/all/export.rb', line 54

def within_max_depth
  @export_depth ||= inherit(:export_depth).to_i + 1
  @export_depth > max_export_depth ? [] : yield
end