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) and can be used independently of Card objects.

Name adds support for deeper integration with Card objects

Defined Under Namespace

Modules: All, CardClass, NameVariants

Constant Summary collapse

ID_MARK_RE =
/^~(?<id>\d+)$/
CODENAME_MARK_RE =
/^:(?<codename>\w+)$/

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?, #reset, #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_joint?, #starts_with_parts?, #valid?

Methods included from Cardname::Contextual

#absolute, #absolute?, #absolute_name, #child_of?, #from, #name_from, #nth_left_name, #relative?, #simple_relative?

Methods included from Cardname::Variants

#decoded, #fully_stripped, #safe_key, #stripped, #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) ⇒ Card::Name

Returns:



20
21
22
23
# File 'card/lib/card/name.rb', line 20

def [] *cardish
  cardish = cardish.first if cardish.size <= 1
  from_cardish(cardish) || unsupported_class!(cardish)
end

.compose(parts) ⇒ Object

interprets symbols/integers as codenames/ids



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

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

.id_from_string(string) ⇒ Integer or nil

translates string identifiers into an id: - string id notation (eg “~75”) - string codename notation (eg “:options”)

Parameters:

  • string (String)

Returns:

  • (Integer or nil)


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

def id_from_string string
  case string
  when ID_MARK_RE       then Regexp.last_match[:id].to_i
  when CODENAME_MARK_RE then Card::Codename.id! Regexp.last_match[:codename]
  end
end

.id_from_string!(string) ⇒ Object



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

def id_from_string! string
  return unless (id = id_from_string string)

  Lexicon.name(id) ? id : bad_mark(string)
end

.new(str, validated_parts = nil) ⇒ Object



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

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

  str = str.to_s

  if !validated_parts && str.include?(joint)
    new_from_compound_string str
  elsif (id = id_from_string str)  # handles ~[id] and :[codename]
    from_id_from_string id, str
  else
    super str
  end
end

.paramsObject



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

def params
  Card::Env.params
end

.sessionObject



25
26
27
# File 'card/lib/card/name.rb', line 25

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

Instance Method Details

#rstar?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'card/lib/card/name.rb', line 119

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

#star?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'card/lib/card/name.rb', line 115

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