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_on_format, ensure_set, extended, format, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, stage_method, view, write_tmp_file
Methods included from Event
#define_event, #event
Instance Method Details
315
316
317
318
319
320
321
322
323
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 315
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
325
326
327
328
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 325
def add_item name
return if include_item? name
self.content = "[[#{(item_names << name).reject(&:blank?) * "]]\n[["}]]"
end
|
#add_item!(name) ⇒ Object
330
331
332
333
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 330
def add_item! name
add_item name
save!
end
|
#diff_args ⇒ Object
260
261
262
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 260
def diff_args
{format: :pointer}
end
|
#drop_item(name) ⇒ Object
335
336
337
338
339
340
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 335
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
342
343
344
345
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 342
def drop_item! name
drop_item name
save!
end
|
#insert_item(index, name) ⇒ Object
347
348
349
350
351
352
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 347
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
354
355
356
357
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 354
def insert_item! index, name
insert_item index, name
save!
end
|
#item_cards(args = {}) ⇒ Object
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 264
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
294
295
296
297
298
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 294
def item_ids args={}
item_names(args).map do |name|
Card.fetch_id name
end.compact
end
|
#item_names(args = {}) ⇒ Object
280
281
282
283
284
285
286
287
288
289
290
291
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 280
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
300
301
302
303
304
305
306
307
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 300
def item_type
opt = options_rule_card
if !opt or opt==self nil
else
opt.item_type
end
end
|
#items=(array) ⇒ Object
309
310
311
312
313
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 309
def items= array
self.content = ''
array.each { |i| self << i }
save!
end
|
#option_cards ⇒ Object
378
379
380
381
382
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 378
def option_cards
option_names.map do |name|
Card.fetch name, new: {}
end
end
|
#option_names ⇒ Object
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 363
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
|
#options_rule_card ⇒ Object
359
360
361
|
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 359
def options_rule_card
rule_card :options
end
|