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

Instance Method Details

#leftString

the part of a compound name to the left of the rightmost joint.

Examples:

"A".cardname.left -> nil
"A+B".cardname.left -> "A"
"A+B+C".cardname.left -> "A+B"
"A+B+C+D".cardname.left -> "A+B+C"

Returns:

  • (String)

See Also:



17
18
19
# File 'cardname/lib/cardname/parts.rb', line 17

def left
  left_name&.s
end

#left_keyString

Returns:

  • (String)

See Also:



23
24
25
# File 'cardname/lib/cardname/parts.rb', line 23

def left_key
  left_name&.key
end

#left_nameCardname

Returns:

See Also:



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_keysArray <String>

Returns:

  • (Array <String>)

See Also:



47
48
49
# File 'cardname/lib/cardname/parts.rb', line 47

def parent_keys
  parent_names.map(&:key)
end

#parent_namesArray <Cardname>

Returns:

See Also:



53
54
55
# File 'cardname/lib/cardname/parts.rb', line 53

def parent_names
  simple? ? [] : [left_name, right_name]
end

#parentsArray <String>

for compound cards, an array of the left and right

Examples:

"A".cardname.parents -> []
"A+B".cardname.parents -> ["A", "B"]
"A+B+C".cardname.parents -> ["A+B", "C"]
"A+B+C+D".cardname.parents -> ["A+B+C", "D"]

Returns:

  • (Array <String>)

See Also:



41
42
43
# File 'cardname/lib/cardname/parts.rb', line 41

def parents
  parent_names.map(&:s)
end

#part_keysArray <String>

Returns:

  • (Array <String>)

See Also:



72
73
74
# File 'cardname/lib/cardname/parts.rb', line 72

def part_keys
  part_names.map(&:key)
end

#part_namesArray <Cardname>

Returns:

See Also:



78
79
80
# File 'cardname/lib/cardname/parts.rb', line 78

def part_names
  @part_names ||= generate_part_names
end

#partsArray <String> Also known as: to_a

for compound cards, each joint separated part

Examples:

"A".cardname.parts -> []
"A+B".cardname.parts -> ["A", "B"]
"A+B+C".cardname.parts -> ["A", "B", "C"]
"A+B+C+D".cardname.parts -> ["A", "B", C", "D"]

Returns:

  • (Array <String>)

See Also:



65
66
67
# File 'cardname/lib/cardname/parts.rb', line 65

def parts
  part_names.map(&:s)
end

#rightString

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"

Returns:

  • (String)

See Also:



138
139
140
# File 'cardname/lib/cardname/parts.rb', line 138

def right
  right_name&.s
end

#right_keyString

Returns:

  • (String)

See Also:



144
145
146
# File 'cardname/lib/cardname/parts.rb', line 144

def right_key
  right_name&.key
end

#right_nameCardname

Returns:

See Also:



150
151
152
# File 'cardname/lib/cardname/parts.rb', line 150

def right_name
  simple? ? nil : part_names[-1]
end

#tagString

like #right, but returns self for simple cards

Examples:

"A".cardname.tag -> "A"
"A+B".cardname.tag -> "B"
"A+B+C".cardname.tag -> "C"
"A+B+C+D".cardname.tag -> "D"

Returns:

  • (String)

See Also:



114
115
116
# File 'cardname/lib/cardname/parts.rb', line 114

def tag
  tag_name.s
end

#tag_keyString

Returns:

  • (String)

See Also:



120
121
122
# File 'cardname/lib/cardname/parts.rb', line 120

def tag_key
  tag_name.key
end

#tag_nameCardname

Returns:

See Also:



126
127
128
# File 'cardname/lib/cardname/parts.rb', line 126

def tag_name
  simple? ? self : right_name
end

#trunkString

like #left, but returns self for simple cards

Examples:

"A".cardname.trunk -> "A"
"A+B".cardname.trunk -> "A"
"A+B+C".cardname.trunk -> "A+B"
"A+B+C+D".cardname.trunk -> "A+B+C"

Returns:

  • (String)

See Also:



90
91
92
# File 'cardname/lib/cardname/parts.rb', line 90

def trunk
  trunk_name.s
end

#trunk_keyString

Returns:

  • (String)

See Also:



96
97
98
# File 'cardname/lib/cardname/parts.rb', line 96

def trunk_key
  trunk_name.key
end

#trunk_nameCardname

Returns:

See Also:



102
103
104
# File 'cardname/lib/cardname/parts.rb', line 102

def trunk_name
  simple? ? self : left_name
end