Class: Cardname

Inherits:
String show all
Extended by:
ClassMethods
Includes:
Contextual, Fields, Manipulate, Parts, Pieces, Predicates, Variants
Defined in:
lib/cardname.rb,
lib/cardname/parts.rb,
lib/cardname/fields.rb,
lib/cardname/pieces.rb,
lib/cardname/variants.rb,
lib/cardname/contextual.rb,
lib/cardname/manipulate.rb,
lib/cardname/predicates.rb,
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.

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 Method Summary collapse

Methods included from ClassMethods

banned_re, cache, new, nothing_banned?, reset, 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_joint?, #starts_with_parts?, #valid?

Methods included from Contextual

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

Methods included from Variants

#decoded, #fully_stripped, #safe_key, #stripped, #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

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ INSTANCE ~~~~~~~~~~~~~~~~~~~~~~~~~



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

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 Method Details

#==(other) ⇒ Boolean

test for same key

Returns:

  • (Boolean)


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

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:



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

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

#keyString

the key defines the namespace

Returns:

  • (String)


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

def key
  @key ||= generate_key.freeze
end

#num_partsInteger

Returns:

  • (Integer)

See Also:



95
96
97
# File 'lib/cardname.rb', line 95

def num_parts
  parts.length
end

#sString Also known as: to_s, to_str

simple string version of name

Returns:

  • (String)


54
55
56
# File 'lib/cardname.rb', line 54

def s
  String.new self
end

#to_nameCardname

Returns:



61
62
63
# File 'lib/cardname.rb', line 61

def to_name
  self
end

#to_symSymbol

Returns:

  • (Symbol)


66
67
68
# File 'lib/cardname.rb', line 66

def to_sym
  s.to_sym
end