Module: Card::Set::Type::Pointer
Instance Method Summary
collapse
Methods included from Card::Set
abstract_set?, all_set?, card_accessor, card_reader, card_writer, clean_empty_module_from_hash, clean_empty_modules, define_active_job, define_event_method, define_event_perform_later_method, define_on_format, ensure_set, event, extended, format, phase_method, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file
Instance Method Details
298
299
300
301
302
303
304
305
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 298
def << item
newname = case item
when Card ; item.name
when Integer ; c = Card[item] and c.name
else item
end
add_item newname
end
|
#add_item(name) ⇒ Object
307
308
309
310
311
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 307
def add_item name
unless include_item? name
self.content="[[#{(item_names << name).reject(&:blank?)*"]]\n[["}]]"
end
end
|
#add_item!(name) ⇒ Object
312
313
314
315
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 312
def add_item! name
add_item name
save!
end
|
#diff_args ⇒ Object
243
244
245
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 243
def diff_args
{format: :pointer}
end
|
#drop_item(name) ⇒ Object
317
318
319
320
321
322
323
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 317
def drop_item name
if 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
end
|
#drop_item!(name) ⇒ Object
324
325
326
327
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 324
def drop_item! name
drop_item name
save!
end
|
#insert_item(index, name) ⇒ Object
329
330
331
332
333
334
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 329
def insert_item index, name
new_names = item_names
new_names.delete(name)
new_names.insert(index,name)
self.content = new_names.map { |name| "[[#{name}]]" }.join "\n"
end
|
#insert_item!(index, name) ⇒ Object
335
336
337
338
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 335
def insert_item! index, name
insert_item index, name
save!
end
|
#item_cards(args = {}) ⇒ Object
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 247
def item_cards args={}
if args[:complete]
query = { referred_to_by: name }.merge args
Card::Query.run query
else
itype = args[:type] || item_type
item_names(args).map do |name|
new_args = itype ? { type: itype } : {}
Card.fetch name, new: new_args
end.compact end
end
|
#item_ids(args = {}) ⇒ Object
277
278
279
280
281
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 277
def item_ids args={}
item_names(args).map do |name|
Card.fetch_id name
end.compact
end
|
#item_names(args = {}) ⇒ Object
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 263
def item_names args={}
context = args[:context] || self.cardname
content = args[:content] || self.raw_content
content.to_s.split(/\n+/).map do |line|
item_name = line.gsub( /\[\[|\]\]/, '').strip
if context == :raw
item_name
else
item_name.to_name.to_absolute context
end
end
end
|
#item_type ⇒ Object
283
284
285
286
287
288
289
290
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 283
def item_type
opt = options_rule_card
if !opt or opt==self nil
else
opt.item_type
end
end
|
#items=(array) ⇒ Object
292
293
294
295
296
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 292
def items= array
self.content=''
array.each { |i| self << i }
save!
end
|
#option_cards ⇒ Object
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 357
def option_cards
result_cards = if oc = options_rule_card
oc.item_cards default_limit: 50, context: name
else
Card.search sort: 'alpha', limit: 50
end
if selected_options = item_names
selected_options.each do |item|
result_cards.push Card.fetch(item,new: {})
end
result_cards.uniq!
end
result_cards
end
|
#option_names ⇒ Object
345
346
347
348
349
350
351
352
353
354
355
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 345
def option_names
result_cards = if oc = options_rule_card
oc.item_names default_limit: 50, context: name
else
Card.search sort: 'name', limit: 50, return: :name
end
if selected_options = item_names
result_cards = result_cards | selected_options
end
result_cards
end
|
#options_rule_card ⇒ Object
341
342
343
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 341
def options_rule_card
self.rule_card :options
end
|