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.
-
#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”).
57 58 59 |
# File 'lib/gamefic/describable.rb', line 57 def definite_article @definite_article || "the" end |
#indefinite_article ⇒ String
The object’s indefinite article (usually “a” or “an”).
25 26 27 |
# File 'lib/gamefic/describable.rb', line 25 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 |
#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.
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
145 146 147 |
# File 'lib/gamefic/describable.rb', line 145 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.
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?
115 116 117 |
# File 'lib/gamefic/describable.rb', line 115 def described? @description.to_s != '' end |
#description ⇒ String
Get the object’s description.
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.
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 |
#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.
41 42 43 |
# File 'lib/gamefic/describable.rb', line 41 def indefinitely (proper_named? || indefinite_article == '' ? '' : "#{indefinite_article} ") + name.to_s end |
#keywords ⇒ Object
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.
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.”
67 68 69 |
# File 'lib/gamefic/describable.rb', line 67 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”.
161 162 163 |
# File 'lib/gamefic/describable.rb', line 161 def to_s indefinitely end |