Module: Card::Set::All::Collection

Extended by:
Card::Set
Defined in:
tmpsets/set/mod002-core/all/collection.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary

Constants included from Format

Format::TEMPLATE_DIR

Instance Method Summary collapse

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#abstract_set?, #all_set?, #num_set_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#all_set_format_mod!, #before, #define_on_format, #format, layout_method_name, #register_set_format, #view, #view_for_override, view_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Instance Method Details

#add_item(item) ⇒ Object



67
68
69
70
# File 'tmpsets/set/mod002-core/all/collection.rb', line 67

def add_item item
  return if include_item? item
  self.content = "#{content}\n#{name}"
end

#collection?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'tmpsets/set/mod002-core/all/collection.rb', line 48

def collection?
  item_cards != [self]
end

#contextual_content(context_card, format_args = {}, view_args = {}) ⇒ Object



124
125
126
127
128
# File 'tmpsets/set/mod002-core/all/collection.rb', line 124

def contextual_content context_card, format_args={}, view_args={}
  context_card.format(format_args).process_content(
    format(format_args)._render_raw(view_args), view_args
  )
end

#drop_item(item) ⇒ Object



72
73
74
75
76
# File 'tmpsets/set/mod002-core/all/collection.rb', line 72

def drop_item item
  return unless include_item? item
  new_names = item_names.reject { |i| i == item }
  self.content = new_names.empty? ? "" : new_names.join("\n")
end

#extended_item_cards(context = nil) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'tmpsets/set/mod002-core/all/collection.rb', line 85

def extended_item_cards context=nil
  context = (context ? context.cardname : cardname)
  args = { limit: "" }
  items = item_cards(args.merge(context: context))
  extended_list = []
  already_extended = ::Set.new # avoid loops

  until items.empty?
    item = items.shift
    next if already_extended.include? item
    already_extended << item
    if item.collection?
      # keep items in order
      items.unshift(*item.item_cards)
    else  # no further level of items
      extended_list << item
    end
  end
  extended_list
end

#extended_item_contents(context = nil) ⇒ Object



106
107
108
# File 'tmpsets/set/mod002-core/all/collection.rb', line 106

def extended_item_contents context=nil
  extended_item_cards(context).map(&:item_names).flatten
end

#extended_list(context = nil) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'tmpsets/set/mod002-core/all/collection.rb', line 110

def extended_list context=nil
  context = (context ? context.cardname : cardname)
  args = { limit: "" }
  item_cards(args.merge(context: context)).map do |x|
    x.item_cards(args)
  end.flatten.map do |x|
    x.item_cards(args)
  end.flatten.map do |y|
    y.item_names(args)
  end.flatten
  # this could go on and on.  more elegant to recurse until you don't have
  # a collection
end

#include_item?(item) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
# File 'tmpsets/set/mod002-core/all/collection.rb', line 62

def include_item? item
  key = item.is_a?(Card) ? item.cardname.key : item.to_name.key
  item_names.map { |name| name.to_name.key }.member? key
end

#insert_item(index, name) ⇒ Object



78
79
80
81
82
83
# File 'tmpsets/set/mod002-core/all/collection.rb', line 78

def insert_item index, name
  new_names = item_names
  new_names.delete name
  new_names.insert index, name
  self.content = new_names.join "\n"
end

#item_cards(_args = {}) ⇒ Object

FIXME: this is inconsistent with item_names



44
45
46
# File 'tmpsets/set/mod002-core/all/collection.rb', line 44

def item_cards _args={} # FIXME: this is inconsistent with item_names
  [self]
end

#item_keys(args = {}) ⇒ Object



56
57
58
59
60
# File 'tmpsets/set/mod002-core/all/collection.rb', line 56

def item_keys args={}
  item_names(args).map do |item|
    item.to_name.key
  end
end

#item_names(_args = {}) ⇒ Object



40
41
42
# File 'tmpsets/set/mod002-core/all/collection.rb', line 40

def item_names _args={}
  format._render_raw.split(/[,\n]/)
end

#item_typeObject



52
53
54
# File 'tmpsets/set/mod002-core/all/collection.rb', line 52

def item_type
  nil
end