Module: Card::Set::All::ItemAssignment

Extended by:
Card::Set
Defined in:
platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb

Overview

Set: All cards (ItemAssignment)

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset

Methods included from I18nScope

#mod_name, #scope

Methods included from Registrar

#extended, #finalize_load, #process_base_modules, #register_set

Methods included from Helpers

#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name

Methods included from Card::Set::AdvancedApi

#assign_type, #attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/mod/collection/set/all/item_assignment.rb"; end

Instance Method Details

#<<(cardish) ⇒ Object

append item to list (does not save)

Parameters:

  • cardish (Cardish)


21
22
23
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 21

def << cardish
  add_item cardish
end

#add_item(cardish) ⇒ Object

append item to list (does not save)

Parameters:



27
28
29
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 27

def add_item cardish
  self.content = item_strings + Array.wrap(cardish)
end

#add_item!(name) ⇒ Object

append item to list and save card

Parameters:



33
34
35
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 33

def add_item! name
  add_item(name) && save!
end

#drop_item(cardish) ⇒ Object

remove item from list

Parameters:



39
40
41
42
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 39

def drop_item cardish
  item_name = cardish.cardname
  self.content = (item_names.reject { |i| i == item_name })
end

#drop_item!(cardish) ⇒ Object

remove item from list and save card

Parameters:



46
47
48
49
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 46

def drop_item! cardish
  drop_item cardish
  save!
end

#duplicate_item_namesObject



92
93
94
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 92

def duplicate_item_names
  item_names.group_by { |e| e }.select { |_k, v| v.size > 1 }.keys
end

#insert_item(index, name) ⇒ Object

insert item into list at specified location

Parameters:

  • index (Integer)

    Array index in which to insert item (0 is first)

  • name (String, Card::Name)

    item name



54
55
56
57
58
59
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 54

def insert_item index, name
  new_names = item_names
  new_names.delete name
  new_names.insert index, name
  self.content = new_names
end

#insert_item!(index, name) ⇒ Object

insert item into list at specified location and save

Parameters:

  • index (Integer)

    Array index in which to insert item (0 is first)

  • name (String, Card::Name)

    item name



64
65
66
67
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 64

def insert_item! index, name
  insert_item index, name
  save!
end

#items=(array) ⇒ Object

set card content based on array and save card

Parameters:

  • array (Array)

    list of strings/names (Cardish)



14
15
16
17
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 14

def items= array
  self.content = array
  save!
end

#items_content(array) ⇒ Object



76
77
78
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 76

def items_content array
  standardized_items(array).to_pointer_content
end

#replace_item(old, new) ⇒ Object



69
70
71
72
73
74
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 69

def replace_item old, new
  return unless include_item? old

  drop_item old
  add_item new
end

#standardize_item(item) ⇒ Object



86
87
88
89
90
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 86

def standardize_item item
  Card::Name[item]
rescue Card::Error::NotFound
  item
end

#standardized_items(array) ⇒ Object



80
81
82
83
84
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 80

def standardized_items array
  array.map! { |i| standardize_item i }.reject!(&:blank?)
  array.uniq! if unique_items?
  array
end

#unique_items?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'platypus/tmp/set/gem-defaults/mod002-collection/all/item_assignment.rb', line 8

def unique_items?
  false
end