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

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

Instance Method Summary collapse

Instance Method Details

#export_items_in_view(view) ⇒ Object



35
36
37
38
39
40
41
# File 'tmpsets/set/mod003-core/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 'tmpsets/set/mod003-core/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 'tmpsets/set/mod003-core/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 'tmpsets/set/mod003-core/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 'tmpsets/set/mod003-core/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 'tmpsets/set/mod003-core/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 'tmpsets/set/mod003-core/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

#within_max_depthObject

prevent recursion



54
55
56
57
# File 'tmpsets/set/mod003-core/all/export.rb', line 54

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