Module: Card::Set::Rstar::Rules

Extended by:
Card::Set
Defined in:
tmpsets/set/mod007-05_standard/rstar/rules.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, phase_method, process_base_module_list, process_base_modules, register_set, register_set_format, shortname, view, write_tmp_file

Instance Method Details

#rule_setObject



332
333
334
335
336
337
338
# File 'tmpsets/set/mod007-05_standard/rstar/rules.rb', line 332

def rule_set
  if is_user_rule?
    self[0..-3]
  else
    trunk
  end
end

#rule_set_keyObject



320
321
322
# File 'tmpsets/set/mod007-05_standard/rstar/rules.rb', line 320

def rule_set_key
  rule_set_name.key
end

#rule_set_nameObject



324
325
326
327
328
329
330
# File 'tmpsets/set/mod007-05_standard/rstar/rules.rb', line 324

def rule_set_name
  if is_user_rule?
    cardname.trunk_name.trunk_name
  else
    cardname.trunk_name
  end
end

#rule_setting_nameObject



340
341
342
# File 'tmpsets/set/mod007-05_standard/rstar/rules.rb', line 340

def rule_setting_name
  cardname.tag
end

#rule_userObject



356
357
358
# File 'tmpsets/set/mod007-05_standard/rstar/rules.rb', line 356

def rule_user
  is_user_rule? ? self[-2] : nil
end

#rule_user_nameObject



352
353
354
# File 'tmpsets/set/mod007-05_standard/rstar/rules.rb', line 352

def rule_user_name
  is_user_rule? ? cardname.trunk_name.tag : nil
end

#rule_user_setting_nameObject



344
345
346
347
348
349
350
# File 'tmpsets/set/mod007-05_standard/rstar/rules.rb', line 344

def rule_user_setting_name
  if is_user_rule?
    "#{rule_user_name}+#{rule_setting_name}"
  else
   rule_setting_name
  end
end

#set_optionsObject

~~~~~~~~~~ determine the set options to which the user can apply the rule.



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'tmpsets/set/mod007-05_standard/rstar/rules.rb', line 362

def set_options

  first =  new_card? ? 0 : set_prototype.set_names.index{|s| s.to_name.key == rule_set_key}
  rule_cnt = 0
  res = []
  fallback_set = nil
  set_prototype.set_names[first..-1].each do |set_name|
    if Card.exists?("#{set_name}+#{rule_user_setting_name}")
      rule_cnt += 1
      res << if rule_cnt == 1
               [set_name,:current]
             else
               fallback_set ||= set_name
               [set_name,:overwritten]
             end
    else
      res << (rule_cnt < 1 ? [set_name,:enabled] : [set_name,:disabled])
    end
  end

  # fallback_set = if first > 0
  #                 res[0..(first-1)].find do |set_name|
  #                   Card.exists?("#{set_name}+#{rule_user_setting_name}")
  #                 end
  #               end
  # last = res.index{|s| s.to_name.key == cardname.trunk_name.key} || -1
  # # note, the -1 can happen with virtual cards because the self set doesn't show up in the set_names.  FIXME!!
  # [res[first..last], fallback_set]
  #
  # The broadest set should always be the currently applied rule
  # (for anything more general, they must explicitly choose to "DELETE" the current one)
  # the narrowest rule should be the one attached to the set being viewed.  So, eg, if you're looking at the "*all plus" set, you shouldn't
  # have the option to create rules based on arbitrary narrower sets, though narrower sets will always apply to whatever prototype we create

  return res, fallback_set
end

#set_prototypeObject



399
400
401
402
403
404
405
# File 'tmpsets/set/mod007-05_standard/rstar/rules.rb', line 399

def set_prototype
  if is_user_rule?
    self[0..-3].prototype
  else
    trunk.prototype
  end
end