Module: Card::Set::Abstract::Pointer::Edit

Extended by:
Card::Set
Defined in:
tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb

Instance Method Summary collapse

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #pattern_and_modules_from_path, #process_base_modules, #register_set, #tmp_file_frame, #tmp_file_template, #tmp_file_wrapped_content, #write_tmp_file

Methods included from Helpers

#abstract_set?, #all_set?, #shortname

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#all_set_format_mod!, #define_on_format, #format, #register_set_format, #view

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

Methods included from Event

#event

Instance Method Details

#<<(item) ⇒ Object



157
158
159
160
161
162
163
164
165
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 157

def << item
  newname =
    case item
    when Card    then item.name
    when Integer then (c = Card[item]) && c.name
    else              item
    end
  add_item newname
end

#add_item(name) ⇒ Object



167
168
169
170
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 167

def add_item name
  return if include_item? name
  self.content = "[[#{(item_names << name).reject(&:blank?) * "]]\n[["}]]"
end

#add_item!(name) ⇒ Object



172
173
174
175
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 172

def add_item! name
  add_item name
  save!
end

#drop_item(name) ⇒ Object



177
178
179
180
181
182
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 177

def drop_item name
  return unless include_item? name
  key = name.to_name.key
  new_names = item_names.reject { |n| n.to_name.key == key }
  self.content = new_names.empty? ? "" : "[[#{new_names * "]]\n[["}]]"
end

#drop_item!(name) ⇒ Object



184
185
186
187
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 184

def drop_item! name
  drop_item name
  save!
end

#insert_item(index, name) ⇒ Object



189
190
191
192
193
194
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 189

def insert_item index, name
  new_names = item_names
  new_names.delete name
  new_names.insert index, name
  self.content = new_names.map { |new_name| "[[#{new_name}]]" }.join "\n"
end

#insert_item!(index, name) ⇒ Object



196
197
198
199
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 196

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

#items=(array) ⇒ Object



151
152
153
154
155
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 151

def items= array
  self.content = ""
  array.each { |i| self << i }
  save!
end

#option_cardsObject



216
217
218
219
220
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 216

def option_cards
  option_names.map do |name|
    Card.fetch name, new: {}
  end
end

#option_namesObject



201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'tmpsets/set/mod004-pointer/abstract/01_pointer/edit.rb', line 201

def option_names
  result_names =
    if (oc = options_rule_card)
      oc.item_names default_limit: 50, context: name
    else
      Card.search({ sort: "name", limit: 50, return: :name },
                  "option names for pointer: #{name}")
    end
  if (selected_options = item_names)
    result_names += selected_options
    result_names.uniq!
  end
  result_names
end