Module: Cardname::Parts
- Included in:
- Cardname
- Defined in:
- cardname/lib/cardname/parts.rb
Overview
naming conventions:
- methods that end with _name return Cardname objects
- methods that end with _key return case/space keys
- methods without _name or _key return Strings
Instance Method Summary collapse
-
#left ⇒ String
the part of a compound name to the left of the rightmost joint.
-
#left_key ⇒ String
-
#left_name ⇒ Cardname
-
#parent_keys ⇒ Array <String>
-
#parent_names ⇒ Array <Cardname>
-
#parents ⇒ Array <String>
for compound cards, an array of the left and right.
-
#part_keys ⇒ Array <String>
-
#part_names ⇒ Array <Cardname>
-
#parts ⇒ Array <String>
(also: #to_a)
for compound cards, each joint separated part.
-
#right ⇒ String
the part of a compound name to the left of the rightmost joint.
-
#right_key ⇒ String
-
#right_name ⇒ Cardname
-
#tag ⇒ String
like #right, but returns self for simple cards.
-
#tag_key ⇒ String
-
#tag_name ⇒ Cardname
-
#trunk ⇒ String
like #left, but returns self for simple cards.
-
#trunk_key ⇒ String
-
#trunk_name ⇒ Cardname
Instance Method Details
#left ⇒ String
the part of a compound name to the left of the rightmost joint.
17 18 19 |
# File 'cardname/lib/cardname/parts.rb', line 17 def left left_name&.s end |
#left_key ⇒ String
23 24 25 |
# File 'cardname/lib/cardname/parts.rb', line 23 def left_key left_name&.key end |
#left_name ⇒ Cardname
29 30 31 |
# File 'cardname/lib/cardname/parts.rb', line 29 def left_name simple? ? nil : self.class.new(part_names[0..-2]) end |
#parent_keys ⇒ Array <String>
47 48 49 |
# File 'cardname/lib/cardname/parts.rb', line 47 def parent_keys parent_names.map(&:key) end |
#parent_names ⇒ Array <Cardname>
53 54 55 |
# File 'cardname/lib/cardname/parts.rb', line 53 def parent_names simple? ? [] : [left_name, right_name] end |
#parents ⇒ Array <String>
for compound cards, an array of the left and right
41 42 43 |
# File 'cardname/lib/cardname/parts.rb', line 41 def parents parent_names.map(&:s) end |
#part_keys ⇒ Array <String>
72 73 74 |
# File 'cardname/lib/cardname/parts.rb', line 72 def part_keys part_names.map(&:key) end |
#part_names ⇒ Array <Cardname>
78 79 80 |
# File 'cardname/lib/cardname/parts.rb', line 78 def part_names @part_names ||= generate_part_names end |
#parts ⇒ Array <String> Also known as: to_a
for compound cards, each joint separated part
65 66 67 |
# File 'cardname/lib/cardname/parts.rb', line 65 def parts part_names.map(&:s) end |
#right ⇒ String
the part of a compound name to the left of the rightmost joint.
"A".cardname.right -> nil
"A+B".cardname.right -> "B"
"A+B+C".cardname.right -> "C"
"A+B+C+D".cardname.right -> "D"
138 139 140 |
# File 'cardname/lib/cardname/parts.rb', line 138 def right right_name&.s end |
#right_key ⇒ String
144 145 146 |
# File 'cardname/lib/cardname/parts.rb', line 144 def right_key right_name&.key end |
#right_name ⇒ Cardname
150 151 152 |
# File 'cardname/lib/cardname/parts.rb', line 150 def right_name simple? ? nil : part_names[-1] end |
#tag ⇒ String
like #right, but returns self for simple cards
114 115 116 |
# File 'cardname/lib/cardname/parts.rb', line 114 def tag tag_name.s end |
#tag_key ⇒ String
120 121 122 |
# File 'cardname/lib/cardname/parts.rb', line 120 def tag_key tag_name.key end |
#tag_name ⇒ Cardname
126 127 128 |
# File 'cardname/lib/cardname/parts.rb', line 126 def tag_name simple? ? self : right_name end |
#trunk ⇒ String
like #left, but returns self for simple cards
90 91 92 |
# File 'cardname/lib/cardname/parts.rb', line 90 def trunk trunk_name.s end |
#trunk_key ⇒ String
96 97 98 |
# File 'cardname/lib/cardname/parts.rb', line 96 def trunk_key trunk_name.key end |
#trunk_name ⇒ Cardname
102 103 104 |
# File 'cardname/lib/cardname/parts.rb', line 102 def trunk_name simple? ? self : left_name end |