Class: Card::Name

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

Constant Summary

Constants inherited from Cardname

Cardname::JOINT_RE, Cardname::OK4KEY_RE

Constants included from Cardname::Contextual

Cardname::Contextual::RELATIVE_REGEXP

Instance Attribute Summary

Attributes inherited from Cardname

#key

Attributes included from Cardname::Parts

#part_keys, #parts, #simple

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NameVariants

#card, #card_id, #codename, #standard, #vary

Methods included from FieldsAndTraits

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

Methods inherited from Cardname

#<<, #==, #[]=, banned_re, cache, cached_name, dangerous_methods, #initialize, nothing_banned?, reset_cache, #s, split_parts, stable_key, stringify, #to_name

Methods included from Cardname::Manipulate

#num_parts, #prepend_joint, #sub_in, #swap, #swap_part, #swap_piece

Methods included from Cardname::Predicates

#compound?, #ends_with_parts?, #include?, #simple?, #starts_with_parts?, #valid?

Methods included from Cardname::Contextual

#absolute, #absolute?, #absolute_name, #child_of?, #from, #name_from, #nth_left, #parts_excluding, #parts_minus, #relative?, #remove_context, #simple_relative?, #starts_with_joint?, #stripped

Methods included from Cardname::Variants

#decoded, #safe_key, #simple_key, #to_sym, #url_key

Methods included from Cardname::Pieces

#pieces

Methods included from Cardname::Parts

#[], #ancestors, #left, #left_key, #left_name, #parent_keys, #parent_names, #parents, #part_names, #piece_names, #right, #right_key, #right_name, #tag, #tag_name, #to_a, #trunk, #trunk_name

Constructor Details

This class inherits a constructor from Cardname

Class Method Details

.[](*cardish) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'card/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 smart_compose cardish
  when String, NilClass then new cardish
  else
    raise ArgumentError, "#{cardish.class} not supported as name identifier"
  end
end

.compose(parts) ⇒ Object



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

def compose parts
  new_from_parts(parts) { |part| new part }
end

.new(str, validated_parts = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'card/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)
    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

.paramsObject



33
34
35
# File 'card/lib/card/name.rb', line 33

def params
  Card::Env.params
end

.sessionObject



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

def session
  Card::Auth.current.name # also_yuck
end

.smart_compose(parts) ⇒ Object

interprets symbols/integers as codenames/ids



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

def smart_compose parts
  new_from_parts(parts) { |part| self[part] }
end

Instance Method Details

#codeObject



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

def code
  Card::Codename[card_id]
end

#rstar?Boolean

Returns:

  • (Boolean)


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

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

#set?Boolean

Returns:

  • (Boolean)


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

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

#setting?Boolean

Returns:

  • (Boolean)


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

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

#star?Boolean

Returns:

  • (Boolean)


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

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