Class: Card::Name

Inherits:
Cardname
  • Object
show all
Includes:
FieldsAndTraits, NameVariants
Defined in:
lib/card/name.rb,
lib/card/name/name_variants.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: FieldsAndTraits, NameVariants

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NameVariants

#vary

Methods included from FieldsAndTraits

#field, #field_name, #field_of?, #field_only?, #relative_field_name, #trait, #trait_name, #trait_name?

Class Method Details

.[](*cardish) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/card/name.rb', line 19

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 smart_compose cardish
  when String, NilClass then new cardish
  else
    raise ArgumentError, "#{cardish.class} not supported as name identifier"
  end
end

.compose(parts) ⇒ Object



51
52
53
54
# File 'lib/card/name.rb', line 51

def compose parts
  name_parts = parts.flatten.map { |part| new part }
  new name_parts.join(joint), true
end

.new(str, validated_parts = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/card/name.rb', line 31

def new str, validated_parts=nil
  return compose str if str.is_a?(Array)

  str = str.to_s

  if !validated_parts && str.include?(joint)
    compose Cardname.split_parts(str)
  elsif (id = Card.id_from_string(str))  # handles ~ and :
    Card.fetch_name(id) { Card.bad_mark(str) }
  else
    super str
  end
end

.smart_compose(parts) ⇒ Object

interprets symbols/integers as codenames/ids



46
47
48
49
# File 'lib/card/name.rb', line 46

def smart_compose parts
  name_parts = parts.flatten.map { |part| self[part] }
  new name_parts.join(joint), true
end

.url_key_to_standard(key) ⇒ Object



56
57
58
# File 'lib/card/name.rb', line 56

def url_key_to_standard key
  key.to_s.tr "_", " "
end

Instance Method Details

#codeObject



69
70
71
# File 'lib/card/name.rb', line 69

def code
  Card::Codename[Card.fetch_id self]
end

#rstar?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/card/name.rb', line 65

def rstar?
  right && "*" == right[0, 1]
end

#set?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/card/name.rb', line 77

def set?
  Set::Pattern.card_keys[tag_name.key]
end

#setting?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/card/name.rb', line 73

def setting?
  Set::Type::Setting.member_names[key]
end

#star?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/card/name.rb', line 61

def star?
  simple? && "*" == s[0, 1]
end