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

Extended by:
Card::Set
Defined in:
tmpsets/set/mod016-standard/rstar/rules.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 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

#rule_setObject



24
25
26
27
28
29
30
# File 'tmpsets/set/mod016-standard/rstar/rules.rb', line 24

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

#rule_set_keyObject



12
13
14
# File 'tmpsets/set/mod016-standard/rstar/rules.rb', line 12

def rule_set_key
  rule_set_name.key
end

#rule_set_nameObject



16
17
18
19
20
21
22
# File 'tmpsets/set/mod016-standard/rstar/rules.rb', line 16

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

#rule_setting_nameObject



32
33
34
# File 'tmpsets/set/mod016-standard/rstar/rules.rb', line 32

def rule_setting_name
  cardname.tag
end

#rule_userObject



48
49
50
# File 'tmpsets/set/mod016-standard/rstar/rules.rb', line 48

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

#rule_user_nameObject



44
45
46
# File 'tmpsets/set/mod016-standard/rstar/rules.rb', line 44

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

#rule_user_setting_nameObject



36
37
38
39
40
41
42
# File 'tmpsets/set/mod016-standard/rstar/rules.rb', line 36

def rule_user_setting_name
  if is_preference?
    "#{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.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'tmpsets/set/mod016-standard/rstar/rules.rb', line 53

def set_options
  first = if new_card?
            0
          else
            set_prototype.set_names.index { |s| s.to_name.key == rule_set_key }
          end
  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

  [res, fallback_set]
end

#set_prototypeObject



97
98
99
100
101
102
103
# File 'tmpsets/set/mod016-standard/rstar/rules.rb', line 97

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