Module: Card::Set::Helpers
- Included in:
- Card::Set
- Defined in:
- lib/card/set/helpers.rb
Constant Summary
collapse
- SET_PATTERN_TEST_REGEXP =
/^(?<pattern>\w+)_set\?$/
Instance Method Summary
collapse
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.
31
32
33
34
35
36
37
|
# File 'lib/card/set/helpers.rb', line 31
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
#num_set_parts(pattern_code) ⇒ Object
16
17
18
19
20
|
# File 'lib/card/set/helpers.rb', line 16
def num_set_parts pattern_code
return 1 if pattern_code == :abstract
Pattern.find(pattern_code).anchor_parts_count
end
|
#pattern_code ⇒ Object
26
27
28
|
# File 'lib/card/set/helpers.rb', line 26
def pattern_code
@pattern_code ||= set_name_parts[2].underscore.to_sym
end
|
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
39
40
41
|
# File 'lib/card/set/helpers.rb', line 39
def respond_to_missing? method_name, _include_private=false
method_name.match? SET_PATTERN_TEST_REGEXP
end
|
#set_name_parts ⇒ Object
22
23
24
|
# File 'lib/card/set/helpers.rb', line 22
def set_name_parts
@set_name_parts ||= name.split "::"
end
|
#shortname ⇒ Object
6
7
8
9
10
|
# File 'lib/card/set/helpers.rb', line 6
def shortname
first = 2 last = first + num_set_parts(pattern_code)
set_name_parts[first..last].join "::"
end
|
#underscore ⇒ Object
12
13
14
|
# File 'lib/card/set/helpers.rb', line 12
def underscore
shortname.tr(":", "_").underscore
end
|