Module: Card::Set::Helpers
- Included in:
- Card::Set
- Defined in:
- card/lib/card/set/helpers.rb
Overview
These helper methods provide easy access to metadata, such as information about the set modified by a module. These methods are seldom used by Monkeys; they are primarily Platypus tools.
Constant Summary collapse
- SET_PATTERN_TEST_REGEXP =
/^(?<pattern>\w+)_set\?$/
Instance Method Summary collapse
-
#format_module(format_sym) ⇒ Object
-
#format_modules(format_sym, test: true) ⇒ Object
-
#method_missing(method_name, *args) ⇒ Object
handles all_set?, abstract_set?, type_set?, etc.
-
#modules ⇒ Object
-
#pattern_code ⇒ Symbol
Codename associated with set’s pattern.
-
#respond_to_missing?(method_name, _include_private = false) ⇒ true/false
handles all_set?, abstract_set?, type_set?, etc.
-
#set_name_parts ⇒ Array
Eg, returns [“Card”, “Set”, “Type”, “User”] for Card::Set::Type::User.
-
#shortname ⇒ String
Card::Set::Type::User.
-
#underscored_name ⇒ String
Card__Set__Type__User for Card::Set::Type::User.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
handles all_set?, abstract_set?, type_set?, etc.
35 36 37 38 39 40 41 |
# File 'card/lib/card/set/helpers.rb', line 35 def method_missing method_name, *args if (matches = method_name.match SET_PATTERN_TEST_REGEXP) pattern_code == matches[:pattern].to_sym else super end end |
Instance Method Details
#format_module(format_sym) ⇒ Object
69 70 71 |
# File 'card/lib/card/set/helpers.rb', line 69 def format_module format_sym const_get Card::Format.format_class_name(format_sym) end |
#format_modules(format_sym, test: true) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'card/lib/card/set/helpers.rb', line 59 def format_modules format_sym, test: true if base_format_modules? [format_module(format_sym)] elsif abstract_set? abstract_format_modules format_sym, test else nonbase_format_modules format_sym end end |
#modules ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'card/lib/card/set/helpers.rb', line 49 def modules if all_set? [self] elsif abstract_set? [test_set] else Set.modules[:nonbase][shortname] || [] end end |
#pattern_code ⇒ Symbol
Returns codename associated with set’s pattern. Eg :type, :right, etc.
30 31 32 |
# File 'card/lib/card/set/helpers.rb', line 30 def pattern_code @pattern_code ||= set_name_parts[2].underscore.to_sym end |
#respond_to_missing?(method_name, _include_private = false) ⇒ true/false
handles all_set?, abstract_set?, type_set?, etc.
45 46 47 |
# File 'card/lib/card/set/helpers.rb', line 45 def respond_to_missing? method_name, _include_private=false method_name.match? SET_PATTERN_TEST_REGEXP end |
#set_name_parts ⇒ Array
Eg, returns [“Card”, “Set”, “Type”, “User”] for Card::Set::Type::User
25 26 27 |
# File 'card/lib/card/set/helpers.rb', line 25 def set_name_parts @set_name_parts ||= name.split "::" end |
#shortname ⇒ String
Card::Set::Type::User
11 12 13 14 15 |
# File 'card/lib/card/set/helpers.rb', line 11 def shortname first = 2 # shortname eliminates Card::Set last = first + num_set_parts(pattern_code) set_name_parts[first..last].join "::" end |
#underscored_name ⇒ String
Card__Set__Type__User for Card::Set::Type::User
19 20 21 |
# File 'card/lib/card/set/helpers.rb', line 19 def underscored_name shortname.tr(":", "_").underscore end |