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
-
#definite_article ⇒ String
Tefinite article for this object (usually “the”).
-
#indefinite_article ⇒ String
The object’s indefinite article (usually “a” or “an”).
-
#name ⇒ String
The object’s name.
-
#nuance ⇒ String
Optional words that shouldn’t match an object on their own but might be used in a larger phrase.
-
#synonyms ⇒ String
Alternate words that can reference the object.
Class Method Summary collapse
-
.default_description ⇒ String
Get the object’s default description.
-
.default_description=(text) ⇒ Object
Set the object’s default description.
Instance Method Summary collapse
-
#definitely ⇒ String
The name of the object with a definite article.
-
#described? ⇒ Boolean
(also: #description?, #has_description?)
Does the object have a description?.
-
#description ⇒ String
Get the object’s description.
-
#description=(text) ⇒ Object
Set the object’s description.
-
#indefinitely ⇒ String
The name of the object with an indefinite article.
- #keywords ⇒ Object
-
#proper_named=(bool) ⇒ Object
Set whether the object has a proper name.
-
#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.”.
-
#to_s ⇒ String
Get a String representation of the object.
Instance Attribute Details
#definite_article ⇒ String
Tefinite article for this object (usually “the”).
70 71 72 |
# File 'lib/gamefic/describable.rb', line 70 def definite_article @definite_article || "the" end |
#indefinite_article ⇒ String
The object’s indefinite article (usually “a” or “an”).
28 29 30 |
# File 'lib/gamefic/describable.rb', line 28 def indefinite_article @indefinite_article end |
#name ⇒ String
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”).
14 15 16 |
# File 'lib/gamefic/describable.rb', line 14 def name @name end |
#nuance ⇒ String
Optional words that shouldn’t match an object on their own but might be used in a larger phrase. For example, if you have an entity named “dog” and its description calls it “sleepy,” you might add “sleepy” to nuance so the phrase “sleepy dog” matches but the word “sleepy” alone does not.
45 46 47 |
# File 'lib/gamefic/describable.rb', line 45 def nuance @nuance ||= '' end |
#synonyms ⇒ String
Alternate words that can reference the object. Synonyms are used in conjunction with the object’s name when scanning tokens.
20 21 22 |
# File 'lib/gamefic/describable.rb', line 20 def synonyms @synonyms end |
Class Method Details
.default_description ⇒ String
Get the object’s default description.
165 166 167 |
# File 'lib/gamefic/describable.rb', line 165 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
158 159 160 |
# File 'lib/gamefic/describable.rb', line 158 def self.default_description=(text) @default_description = text end |
Instance Method Details
#definitely ⇒ String
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.
63 64 65 |
# File 'lib/gamefic/describable.rb', line 63 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?
128 129 130 |
# File 'lib/gamefic/describable.rb', line 128 def described? @description.to_s != '' end |
#description ⇒ String
Get the object’s description.
137 138 139 |
# File 'lib/gamefic/describable.rb', line 137 def description @description || format(Describable.default_description, name: definitely, Name: definitely.capitalize_first) end |
#description=(text) ⇒ Object
Set the object’s description.
144 145 146 |
# File 'lib/gamefic/describable.rb', line 144 def description=(text) @description = (text if text != (format(Describable.default_description, name: definitely, Name: definitely.capitalize_first))) end |
#indefinitely ⇒ String
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.
54 55 56 |
# File 'lib/gamefic/describable.rb', line 54 def indefinitely (proper_named? || indefinite_article == '' ? '' : "#{indefinite_article} ") + name.to_s end |
#keywords ⇒ Object
35 36 37 |
# File 'lib/gamefic/describable.rb', line 35 def keywords "#{name} #{synonyms}".keywords end |
#proper_named=(bool) ⇒ Object
Set whether the object has a proper name.
87 88 89 90 91 92 93 |
# File 'lib/gamefic/describable.rb', line 87 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.”
80 81 82 |
# File 'lib/gamefic/describable.rb', line 80 def proper_named? @proper_named == true end |
#to_s ⇒ String
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”.
174 175 176 |
# File 'lib/gamefic/describable.rb', line 174 def to_s indefinitely end |