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.
45
46
47
48
49
50
51
|
# File 'lib/card/set/helpers.rb', line 45
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
79
80
81
|
# File 'lib/card/set/helpers.rb', line 79
def format_module format_sym
const_get Card::Format.format_class_name(format_sym)
end
|
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/card/set/helpers.rb', line 67
def format_modules format_sym
type_key = set_format_type_key
if !type_key || type_key == :base_format
[format_module(format_sym)]
elsif abstract_set?
[test_set.format_module(format_sym)]
else
format_class = Card::Format.format_class format: format_sym
Card::Set.modules[type_key][format_class][shortname] || []
end
end
|
#modules ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'lib/card/set/helpers.rb', line 57
def modules
if all_set?
[self]
elsif abstract_set?
[test_set]
else
Set.modules[:nonbase][shortname] || []
end
end
|
#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
40
41
42
|
# File 'lib/card/set/helpers.rb', line 40
def pattern_code
@pattern_code ||= set_name_parts[2].underscore.to_sym
end
|
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
53
54
55
|
# File 'lib/card/set/helpers.rb', line 53
def respond_to_missing? method_name, _include_private=false
method_name.match? SET_PATTERN_TEST_REGEXP
end
|
22
23
24
|
# File 'lib/card/set/helpers.rb', line 22
def set_format_type_key
:"#{set_type_key}_format"
end
|
#set_name_parts ⇒ Object
36
37
38
|
# File 'lib/card/set/helpers.rb', line 36
def set_name_parts
@set_name_parts ||= name.split "::"
end
|
#set_type_key ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/card/set/helpers.rb', line 26
def set_type_key
if all_set?
:base
elsif abstract_set?
:abstract
else
:nonbase
end
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
|
#test_set ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/card/set/helpers.rb', line 83
def test_set
::Card::Set::Self.const_remove_if_defined :TestSet
eval <<-RUBY, binding, __FILE__, __LINE__ + 1
class ::Card::Set::Self
module TestSet
extend Card::Set
include_set #{name}
end
end
RUBY
::Card::Set::Self::TestSet
end
|
#underscore ⇒ Object
12
13
14
|
# File 'lib/card/set/helpers.rb', line 12
def underscore
shortname.tr(":", "_").underscore
end
|