Class: Card::Name
- Inherits:
-
Cardname
- Object
- Cardname
- Card::Name
- Includes:
- FieldsAndTraits, NameVariants
- Defined in:
- lib/card/name.rb,
lib/card/name/all.rb,
lib/card/name/all/parts.rb,
lib/card/name/card_class.rb,
lib/card/name/name_variants.rb,
lib/card/name/all/descendants.rb,
lib/card/name/fields_and_traits.rb
Overview
The Cardname class provides generalized of Card naming patterns (compound names, key-based variants, etc)
Card::Name adds support for deeper card integration
Defined Under Namespace
Modules: All, CardClass, FieldsAndTraits, NameVariants
Class Method Summary collapse
- .[](*cardish) ⇒ Object
-
.compose(parts) ⇒ Object
interprets symbols/integers as codenames/ids.
- .new(str, validated_parts = nil) ⇒ Object
- .params ⇒ Object
- .session ⇒ Object
Instance Method Summary collapse
Methods included from NameVariants
#card, #card_id, #codename, #codename_or_string, #standard, #vary
Methods included from FieldsAndTraits
#field, #field_name, #field_of?, #field_only?, #relative_field_name
Class Method Details
.[](*cardish) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/card/name.rb', line 17 def [] *cardish cardish = cardish.first if cardish.size <= 1 case cardish when Card then cardish.name when Symbol, Integer then Card.fetch_name(cardish) when Array then compose cardish when String, NilClass then new cardish else raise ArgumentError, "#{cardish.class} not supported as name identifier" end end |
.compose(parts) ⇒ Object
interprets symbols/integers as codenames/ids
52 53 54 |
# File 'lib/card/name.rb', line 52 def compose parts new_from_parts(parts) { |part| self[part] } end |
.new(str, validated_parts = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/card/name.rb', line 37 def new str, validated_parts=nil return compose str if str.is_a?(Array) str = str.to_s if !validated_parts && str.include?(joint) string_compose Cardname.split_parts(str) elsif (id = Card.id_from_string str) # handles ~[id] and :[codename] Card.name_from_id_from_string id, str else super str end end |
Instance Method Details
#rstar? ⇒ Boolean
72 73 74 |
# File 'lib/card/name.rb', line 72 def rstar? right && right[0, 1] == "*" end |
#star? ⇒ Boolean
68 69 70 |
# File 'lib/card/name.rb', line 68 def star? simple? && s[0, 1] == "*" end |