Class: Card::Name

Inherits:
Cardname show all
Includes:
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

Overview

The Cardname class provides generalized of Card naming patterns (compound names, key-based variants, etc)

Name adds support for deeper card integration

Defined Under Namespace

Modules: All, CardClass, 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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NameVariants

#alternative, #card, #card_id, #codename, #codename_or_string, #standard, #vary

Methods inherited from Cardname

#==, #[], #initialize, #num_parts, #s, #to_name, #to_sym

Methods included from Cardname::ClassMethods

#banned_re, #cache, #new, #nothing_banned?, #split_parts

Methods included from Cardname::Fields

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

Methods included from Cardname::Manipulate

#<<, #[]=, #prepend_joint, #sub_in, #swap

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, #relative?, #simple_relative?, #starts_with_joint?, #stripped

Methods included from Cardname::Variants

#decoded, #safe_key, #simple_key, #url_key

Methods included from Cardname::Pieces

#ancestor_pieces, #ancestors, #piece_names, #pieces

Methods included from Cardname::Parts

#left, #left_key, #left_name, #parent_keys, #parent_names, #parents, #part_keys, #part_names, #parts, #right, #right_key, #right_name, #tag, #tag_key, #tag_name, #trunk, #trunk_key, #trunk_name

Constructor Details

This class inherits a constructor from Cardname

Class Method Details

.[](*cardish) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'card/lib/card/name.rb', line 16

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



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

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

.new(str, validated_parts = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'card/lib/card/name.rb', line 36

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

.paramsObject



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

def params
  Card::Env.params
end

.sessionObject



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

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

Instance Method Details

#rstar?Boolean

Returns:

  • (Boolean)


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

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

#star?Boolean

Returns:

  • (Boolean)


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

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