Module: Card::Set::Rule::Rules
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod022-rules/rule/rules.rb
Overview
Set: All rule cards (Rules)
Class Method Summary collapse
Instance Method Summary collapse
-
#first_set_option_index(candidates) ⇒ Object
the narrowest rule should be the one attached to the set being viewed.
- #rule_set ⇒ Object
- #rule_set_key ⇒ Object
- #rule_set_name ⇒ Object
- #rule_setting_name ⇒ Object
- #rule_setting_title ⇒ Object
- #rule_user_setting_name ⇒ Object
-
#set_options ⇒ Object
~~~~~~~~~~ determine the set options to which a user can apply the rule.
- #set_prototype ⇒ Object
- #short_help_text ⇒ Object
- #tally_set_option(set_name, tally) ⇒ Object
Methods included from I18nScope
Methods included from Loader
#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set
Methods included from Helpers
#abstract_set?, #all_set?, #num_set_parts, #shortname, #underscore
Methods included from AdvancedApi
#attachment, #ensure_set, #stage_method
Methods included from Format
#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name
Methods included from Inheritance
#include_set, #include_set_formats
Methods included from Basket
#abstract_basket, #add_to_basket, #basket, #unshift_basket
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Class Method Details
.source_location ⇒ Object
7 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 7 def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/rules/set/rule/rules.rb"; end |
Instance Method Details
#first_set_option_index(candidates) ⇒ Object
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
81 82 83 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 81 def first_set_option_index candidates new_card? ? 0 : candidates.index { |c| c.to_name.key == rule_set_key } end |
#rule_set ⇒ Object
27 28 29 30 31 32 33 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 27 def rule_set if is_preference? self[0..-3] else trunk end end |
#rule_set_key ⇒ Object
15 16 17 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 15 def rule_set_key rule_set_name.key end |
#rule_set_name ⇒ Object
19 20 21 22 23 24 25 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 19 def rule_set_name if is_preference? name.trunk_name.trunk_name else name.trunk_name end end |
#rule_setting_name ⇒ Object
35 36 37 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 35 def rule_setting_name name.tag end |
#rule_setting_title ⇒ Object
43 44 45 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 43 def rule_setting_title rule_setting_name.tr "*", "" end |
#rule_user_setting_name ⇒ Object
47 48 49 50 51 52 53 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 47 def rule_user_setting_name if is_preference? "#{rule_user_name}+#{rule_setting_name}" else rule_setting_name end end |
#set_options ⇒ Object
~~~~~~~~~~ determine the set options to which a user can apply the rule.
56 57 58 59 60 61 62 63 64 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 56 def candidates = set_prototype.set_names first = first_set_option_index candidates tally = { existing: 0, options: [] } candidates[first..-1].each do |set_name| tally_set_option set_name, tally end tally[:options] end |
#set_prototype ⇒ Object
85 86 87 88 89 90 91 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 85 def set_prototype if is_preference? self[0..-3].prototype else trunk.prototype end end |
#short_help_text ⇒ Object
39 40 41 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 39 def short_help_text Card[rule_setting_name].short_help_text end |
#tally_set_option(set_name, tally) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'tmpsets/set/mod022-rules/rule/rules.rb', line 66 def tally_set_option set_name, tally state = if Card.exists?("#{set_name}+#{rule_user_setting_name}") tally[:existing] += 1 tally[:existing] == 1 ? :current : :overwritten else tally[:existing] < 1 ? :enabled : :disabled end tally[:options] << [set_name, state] end |