Module: Card::Set::Type::Pointer

Extended by:
Card::Set
Included in:
Right::Followers, Session, Skin, Card::Set::TypePlusRight::User::Follow
Defined in:
tmpsets/set/mod003-02_basic_types/type/pointer.rb

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, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file

Instance Method Details

#<<(item) ⇒ Object



282
283
284
285
286
287
288
289
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 282

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



291
292
293
294
295
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 291

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

#add_item!(name) ⇒ Object



296
297
298
299
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 296

def add_item! name
  add_item name
  save!
end

#diff_argsObject



227
228
229
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 227

def diff_args
  {:format => :pointer}
end

#drop_item(name) ⇒ Object



301
302
303
304
305
306
307
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 301

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



308
309
310
311
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 308

def drop_item! name
  drop_item name
  save!
end

#insert_item(index, name) ⇒ Object



313
314
315
316
317
318
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 313

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



319
320
321
322
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 319

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

#item_cards(args = {}) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 231

def item_cards args={}
  if args[:complete]
    #warn "item_card[#{args.inspect}], :complete"
    Card::Query.new({:referred_to_by=>name}.merge(args)).run
  else

    itype = args[:type] || item_type
    #warn "item_card[#{inspect}], :complete"
    item_names(args).map do |name|
      new_args = itype ? { :type=>itype } : {}
      Card.fetch name, :new=>new_args
    end.compact # compact?  can't be nil, right?
  end
end

#item_ids(args = {}) ⇒ Object



261
262
263
264
265
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 261

def item_ids args={}
  item_names(args).map do |name|
    Card.fetch_id name
  end.compact
end

#item_names(args = {}) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
258
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 247

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_typeObject



267
268
269
270
271
272
273
274
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 267

def item_type
  opt = options_rule_card
  if !opt or opt==self #fixme, need better recursion prevention
    nil
  else
    opt.item_type
  end
end

#items=(array) ⇒ Object



276
277
278
279
280
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 276

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

#option_cardsObject



341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 341

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_namesObject



329
330
331
332
333
334
335
336
337
338
339
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 329

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_cardObject



325
326
327
# File 'tmpsets/set/mod003-02_basic_types/type/pointer.rb', line 325

def options_rule_card
  self.rule_card :options
end