Class: Cardname

Inherits:
String show all
Extended by:
ClassMethods
Includes:
Contextual, Fields, Manipulate, Parts, Pieces, Predicates, Variants
Defined in:
cardname/lib/cardname.rb,
cardname/lib/cardname/parts.rb,
cardname/lib/cardname/fields.rb,
cardname/lib/cardname/pieces.rb,
cardname/lib/cardname/variants.rb,
cardname/lib/cardname/contextual.rb,
cardname/lib/cardname/manipulate.rb,
cardname/lib/cardname/predicates.rb,
cardname/lib/cardname/class_methods.rb

Overview

The Cardname class generalizes the core naming concepts of Decko/Card. The most central of these is the idea that compound names can be formed by combining simple names.

Direct Known Subclasses

Card::Name

Defined Under Namespace

Modules: ClassMethods, Contextual, Fields, Manipulate, Parts, Pieces, Predicates, Variants

Constant Summary collapse

OK4KEY_RE =
'\p{Word}\*'
JOINT_RE =
Regexp.escape joint

Constants included from Contextual

Contextual::RELATIVE_REGEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

banned_re, cache, new, nothing_banned?, split_parts

Methods included from Fields

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

Methods included from Manipulate

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

Methods included from Predicates

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

Methods included from Contextual

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

Methods included from Variants

#decoded, #safe_key, #simple_key, #url_key

Methods included from Pieces

#ancestor_pieces, #ancestors, #piece_names, #pieces

Methods included from 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

#initialize(str) ⇒ Cardname

Returns a new instance of Cardname.



44
45
46
47
48
49
50
51
52
# File 'cardname/lib/cardname.rb', line 44

def initialize str
  super str
  strip!
  encode! "UTF-8"
  part_names # populates @part_names and @simple
  decoded # populates @decoded
  key # populates and freezes @key
  freeze
end

Instance Attribute Details

#keyString (readonly)

the key defines the namespace

Returns:

  • (String)


42
43
44
# File 'cardname/lib/cardname.rb', line 42

def key
  @key
end

Instance Method Details

#==(other) ⇒ Boolean

test for same key

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
# File 'cardname/lib/cardname.rb', line 80

def == other
  key ==
    case
    when other.respond_to?(:key)     then other.key
    when other.respond_to?(:to_name) then other.to_name.key
    else                                  other.to_s.to_name.key
    end
end

#[](*args) ⇒ Cardname

cardname based on part index

Returns:



91
92
93
# File 'cardname/lib/cardname.rb', line 91

def [] *args
  self.class.new part_names[*args]
end

#num_partsInteger

Returns:

  • (Integer)

See Also:



97
98
99
# File 'cardname/lib/cardname.rb', line 97

def num_parts
  parts.length
end

#sString Also known as: to_s, to_str

simple string version of name

Returns:

  • (String)


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

def s
  String.new self
end

#to_nameCardname

Returns:



63
64
65
# File 'cardname/lib/cardname.rb', line 63

def to_name
  self
end

#to_symSymbol

Returns:

  • (Symbol)


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

def to_sym
  s.to_sym
end