Module: Gamefic::Describable
Overview
Add a variety of text properties for naming, describing, and referencing objects.
Constant Summary
Constants included from Keywords
Instance Attribute Summary collapse
-
#definite_article ⇒ String
Get the definite article for this object (usually “the”).
-
#indefinite_article ⇒ String
The object’s indefinite article (usually “a” or “an”).
-
#name ⇒ String
Get the name of the object.
-
#synonyms ⇒ String
Alternate words that can be used to describe 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
Get the name of the object with a definite article.
-
#description ⇒ String
Get the object’s description.
-
#description=(text) ⇒ Object
Set the object’s description.
-
#has_description? ⇒ Boolean
Does the object have a description?.
-
#indefinitely ⇒ String
Get the name of the object with an indefinite article.
-
#keywords ⇒ Array<String>
Get a set of keywords associated with the 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.
Methods included from Keywords
Instance Attribute Details
#definite_article ⇒ String
Get the definite article for this object (usually “the”).
29 30 31 |
# File 'lib/gamefic/describable.rb', line 29 def definite_article @definite_article end |
#indefinite_article ⇒ String
The object’s indefinite article (usually “a” or “an”).
24 25 26 |
# File 'lib/gamefic/describable.rb', line 24 def indefinite_article @indefinite_article end |
#name ⇒ String
Get the name of the object. The name is 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”).
13 14 15 |
# File 'lib/gamefic/describable.rb', line 13 def name @name end |
#synonyms ⇒ String
Alternate words that can be used to describe the object. Synonyms are used in conjunction with the object’s name when generating keywords.
19 20 21 |
# File 'lib/gamefic/describable.rb', line 19 def synonyms @synonyms end |
Class Method Details
.default_description ⇒ String
Get the object’s default description.
177 178 179 |
# File 'lib/gamefic/describable.rb', line 177 def self.default_description @default_description || "There's nothing special about %{name}." 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
170 171 172 |
# File 'lib/gamefic/describable.rb', line 170 def self.default_description=(text) @default_description = text end |
Instance Method Details
#definitely ⇒ String
Get 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.
53 54 55 |
# File 'lib/gamefic/describable.rb', line 53 def definitely ((proper_named? or definite_article == '') ? '' : "#{definite_article} ") + name.to_s end |
#description ⇒ String
Get the object’s description.
144 145 146 |
# File 'lib/gamefic/describable.rb', line 144 def description @description || (Describable.default_description % { :name => self.definitely, :Name => self.definitely.capitalize_first }) end |
#description=(text) ⇒ Object
Set the object’s description.
151 152 153 154 155 156 157 |
# File 'lib/gamefic/describable.rb', line 151 def description=(text) if text != (Describable.default_description % { :name => self.definitely, :Name => self.definitely.capitalize_first }) @description = text else @description = nil end end |
#has_description? ⇒ Boolean
Does the object have a description?
137 138 139 |
# File 'lib/gamefic/describable.rb', line 137 def has_description? (@description.to_s != '') end |
#indefinitely ⇒ String
Get 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.
44 45 46 |
# File 'lib/gamefic/describable.rb', line 44 def indefinitely ((proper_named? or indefinite_article == '') ? '' : "#{indefinite_article} ") + name.to_s end |
#keywords ⇒ Array<String>
Get a set of keywords associated with the object. Keywords are typically the words in the object’s name plus its synonyms.
35 36 37 |
# File 'lib/gamefic/describable.rb', line 35 def keywords @keywords ||= "#{definite_article} #{indefinite_article} #{name} #{synonyms}".downcase.split(Keywords::SPLIT_REGEXP).uniq end |
#proper_named=(bool) ⇒ Object
Set whether the object has a proper name.
93 94 95 96 97 98 99 100 101 |
# File 'lib/gamefic/describable.rb', line 93 def proper_named=(bool) if bool == true if @definite_article != nil @name = "#{@definite_article} #{@name}" @definite_article = nil end 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.”
86 87 88 |
# File 'lib/gamefic/describable.rb', line 86 def proper_named? (@proper_named == true) end |
#to_s ⇒ String
Get a String representation of the object. By default, this is the object’s name with an indefinite article, e.g., “a person” or “a red dog.”
186 187 188 |
# File 'lib/gamefic/describable.rb', line 186 def to_s indefinitely end |