Class: Card::Name

Inherits:
SmartName
  • Object
show all
Includes:
FieldsAndTraits, Variants
Defined in:
lib/card/name.rb,
lib/card/name/variants.rb,
lib/card/name/view_name.rb,
lib/card/name/fields_and_traits.rb

Overview

The SmartName 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, Variants Classes: ViewName

Constant Summary collapse

RELATIVE_REGEXP =
/\b_(left|right|whole|self|user|main|\d+|L*R?)\b/

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Variants

#vary

Methods included from FieldsAndTraits

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

Class Method Details

.cardish(mark) ⇒ Object



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

def cardish mark
  case mark
  when Card            then mark.cardname
  when Symbol, Integer then Card.quick_fetch(mark).cardname
  else                      mark.to_name
  end
end

.url_key_to_standard(key) ⇒ Object



30
31
32
# File 'lib/card/name.rb', line 30

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

Instance Method Details

#absolute?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/card/name.rb', line 81

def absolute?
  !relative?
end

#absolute_name(context_name) ⇒ Object



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

def absolute_name context_name
  to_absolute_name(context_name)
end

#child_of?(context_name) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
# File 'lib/card/name.rb', line 55

def child_of? context_name
  if context_name.present?
    # Do I still equal myself after I've been relativised in the context
    # of context_name?
    relative_name(context_name).key != absolute_name(context_name).key
  else
    s.match(/^\s*\+/)
  end
end

#codeObject



43
44
45
# File 'lib/card/name.rb', line 43

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

#relative?Boolean

Returns:

  • (Boolean)


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

def relative?
  s =~ RELATIVE_REGEXP || starts_with_joint?
end

#relative_name(context_name) ⇒ Object



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

def relative_name context_name
  to_show(*context_name.to_name.parts).to_name
end

#rstar?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/card/name.rb', line 39

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

#set?Boolean

Returns:

  • (Boolean)


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

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

#setting?Boolean

Returns:

  • (Boolean)


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

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

#simple_relative?Boolean

Returns:

  • (Boolean)


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

def simple_relative?
  relative? && stripped.to_name.starts_with_joint?
end

#star?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/card/name.rb', line 35

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

#starts_with_joint?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/card/name.rb', line 89

def starts_with_joint?
  s =~ /^\+/
end

#strippedObject



85
86
87
# File 'lib/card/name.rb', line 85

def stripped
  s.gsub RELATIVE_REGEXP, ""
end

#title(title_directive, context_names) ⇒ Object

processes contextual title argument used in nests like "title: _left"



98
99
100
# File 'lib/card/name.rb', line 98

def title title_directive, context_names
  title_directive.to_name.to_absolute_name(self).to_show(*context_names)
end

#to_symObject



93
94
95
# File 'lib/card/name.rb', line 93

def to_sym
  s.to_sym
end