Module: Gamefic::Describable

Included in:
Entity
Defined in:
lib/gamefic/describable.rb

Overview

A variety of text properties for naming, describing, and referencing objects.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#definite_articleString

Tefinite article for this object (usually “the”).

Returns:



57
58
59
# File 'lib/gamefic/describable.rb', line 57

def definite_article
  @definite_article || "the"
end

#indefinite_articleString

The object’s indefinite article (usually “a” or “an”).

Returns:



25
26
27
# File 'lib/gamefic/describable.rb', line 25

def indefinite_article
  @indefinite_article
end

#nameString

The object’s name. Names are usually presented without articles (e.g., “object” instead of “an object” or “the object”) unless the article is part of a proper name (e.g., “The Ohio State University”).

Returns:



14
15
16
# File 'lib/gamefic/describable.rb', line 14

def name
  @name
end

#synonymsString

Alternate words that can reference the object. Synonyms are used in conjunction with the object’s name when scanning tokens.

Returns:



20
21
22
# File 'lib/gamefic/describable.rb', line 20

def synonyms
  @synonyms
end

Class Method Details

.default_descriptionString

Get the object’s default description.

Returns:



152
153
154
# File 'lib/gamefic/describable.rb', line 152

def self.default_description
  @default_description || "There's nothing special about %<name>s."
end

.default_description=(text) ⇒ Object

Set the object’s default description. The default description is typically set in an object’s initialization to ensure that a non-empty string is available when a instance-specific description is not provided

Parameters:



145
146
147
# File 'lib/gamefic/describable.rb', line 145

def self.default_description=(text)
  @default_description = text
end

Instance Method Details

#definitelyString

The name of the object with a definite article. Note: proper-named objects never append an article, though an article may be included in its proper name.

Returns:



50
51
52
# File 'lib/gamefic/describable.rb', line 50

def definitely
  (proper_named? || definite_article == '' ? '' : "#{definite_article} ") + name.to_s
end

#described?Boolean Also known as: description?, has_description?

Does the object have a description?

Returns:

  • (Boolean)


115
116
117
# File 'lib/gamefic/describable.rb', line 115

def described?
  @description.to_s != ''
end

#descriptionString

Get the object’s description.

Returns:



124
125
126
# File 'lib/gamefic/describable.rb', line 124

def description
  @description || format(Describable.default_description, name: definitely, Name: definitely.capitalize_first)
end

#description=(text) ⇒ Object

Set the object’s description.

Parameters:



131
132
133
# File 'lib/gamefic/describable.rb', line 131

def description=(text)
  @description = (text if text != (format(Describable.default_description, name: definitely, Name: definitely.capitalize_first)))
end

#indefinitelyString

The name of the object with an indefinite article. Note: proper-named objects never append an article, though an article may be included in its proper name.

Returns:



41
42
43
# File 'lib/gamefic/describable.rb', line 41

def indefinitely
  (proper_named? || indefinite_article == '' ? '' : "#{indefinite_article} ") + name.to_s
end

#keywordsObject



32
33
34
# File 'lib/gamefic/describable.rb', line 32

def keywords
  "#{name} #{synonyms}".keywords
end

#proper_named=(bool) ⇒ Object

Set whether the object has a proper name.

Parameters:

  • bool (Boolean)


74
75
76
77
78
79
80
# File 'lib/gamefic/describable.rb', line 74

def proper_named=(bool)
  if bool && @definite_article
    @name = "#{@definite_article} #{@name}".strip
    @definite_article = nil
  end
  @proper_named = bool
end

#proper_named?Boolean

Is the object proper-named? Proper-named objects typically do not add articles to their names when referenced #definitely or #indefinitely, e.g., “Jane Doe” instead of “a Jane Doe” or “the Jane Doe.”

Returns:

  • (Boolean)


67
68
69
# File 'lib/gamefic/describable.rb', line 67

def proper_named?
  @proper_named == true
end

#to_sString

Get a String representation of the object. By default, this is either the object’s name with an indefinite article, e.g., “a person” or “a red dog”; or its proper name, e.g., “Mr. Smith”.

Returns:



161
162
163
# File 'lib/gamefic/describable.rb', line 161

def to_s
  indefinitely
end