Module: Gamefic::Describable
- Includes:
- Grammar::Person, Grammar::Plural, Matchable
- Included in:
- Entity
- Defined in:
- lib/gamefic/describable.rb
Overview
Add a variety of text properties for naming, describing, and referencing objects.
Constant Summary
Constants included from Matchable
Instance Attribute Summary collapse
-
#definite_article ⇒ String
Get the definite article for this object.
- #indefinite_article ⇒ String
- #name ⇒ String
- #synonyms ⇒ String
Attributes included from Grammar::Person
Attributes included from Grammar::Plural
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 ⇒ Object
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 ⇒ Keywords
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 Matchable
Methods included from Grammar::Plural
Instance Attribute Details
#definite_article ⇒ String
Get the definite article for this object.
22 23 24 |
# File 'lib/gamefic/describable.rb', line 22 def definite_article @definite_article end |
#indefinite_article ⇒ String
19 20 21 |
# File 'lib/gamefic/describable.rb', line 19 def indefinite_article @indefinite_article end |
Class Method Details
.default_description ⇒ String
Get the object’s default description.
162 163 164 |
# File 'lib/gamefic/describable.rb', line 162 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
155 156 157 |
# File 'lib/gamefic/describable.rb', line 155 def self.default_description=(text) @default_description = text end |
Instance Method Details
#definitely ⇒ Object
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.
44 45 46 |
# File 'lib/gamefic/describable.rb', line 44 def definitely ((proper_named? or definite_article == '') ? '' : "#{definite_article} ") + name.to_s end |
#description ⇒ String
Get the object’s description.
129 130 131 |
# File 'lib/gamefic/describable.rb', line 129 def description @description || (Describable.default_description % { :name => self.definitely, :Name => self.definitely.capitalize_first }) end |
#description=(text) ⇒ Object
Set the object’s description.
136 137 138 139 140 141 142 |
# File 'lib/gamefic/describable.rb', line 136 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?
122 123 124 |
# File 'lib/gamefic/describable.rb', line 122 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.
37 38 39 |
# File 'lib/gamefic/describable.rb', line 37 def indefinitely ((proper_named? or indefinite_article == '') ? '' : "#{indefinite_article} ") + name.to_s end |
#keywords ⇒ Keywords
Get a set of Keywords associated with the object. Keywords are typically the words in the object’s name plus its synonyms.
28 29 30 |
# File 'lib/gamefic/describable.rb', line 28 def keywords @keywords ||= "#{definite_article} #{indefinite_article} #{name} #{synonyms}".downcase.split(Matchable::SPLIT_REGEXP).uniq end |
#proper_named=(bool) ⇒ Object
Set whether the object has a proper name.
78 79 80 81 82 83 84 85 86 |
# File 'lib/gamefic/describable.rb', line 78 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.”
71 72 73 |
# File 'lib/gamefic/describable.rb', line 71 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.”
171 172 173 |
# File 'lib/gamefic/describable.rb', line 171 def to_s indefinitely end |