Module: Gamefic::Describable
- Includes:
- Grammar::Person, Grammar::Plural
- Included in:
- Entity
- Defined in:
- lib/gamefic/describable.rb
Overview
Add a variety of text properties for naming, describing, and properly referencing objects.
Instance Attribute Summary collapse
-
#definite_article ⇒ String
Get the definite article for this object.
-
#indefinite_article ⇒ Object
Returns the value of attribute indefinite_article.
-
#name ⇒ Object
Returns the value of attribute name.
-
#synonyms ⇒ Object
Returns the value of attribute synonyms.
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 Grammar::Plural
Instance Attribute Details
#definite_article ⇒ String
Get the definite article for this object.
41 42 43 |
# File 'lib/gamefic/describable.rb', line 41 def definite_article @definite_article || "the" end |
#indefinite_article ⇒ Object
Returns the value of attribute indefinite_article.
11 12 13 |
# File 'lib/gamefic/describable.rb', line 11 def indefinite_article @indefinite_article end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/gamefic/describable.rb', line 10 def name @name end |
#synonyms ⇒ Object
Returns the value of attribute synonyms.
11 12 13 |
# File 'lib/gamefic/describable.rb', line 11 def synonyms @synonyms end |
Class Method Details
.default_description ⇒ String
Get the object’s default description.
136 137 138 |
# File 'lib/gamefic/describable.rb', line 136 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
129 130 131 |
# File 'lib/gamefic/describable.rb', line 129 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.
34 35 36 |
# File 'lib/gamefic/describable.rb', line 34 def definitely ((proper_named? or definite_article == '') ? '' : "#{definite_article} ") + name end |
#description ⇒ String
Get the object’s description.
108 109 110 |
# File 'lib/gamefic/describable.rb', line 108 def description @description || (Describable.default_description % { :name => self.definitely, :Name => self.definitely.capitalize_first }) end |
#description=(text) ⇒ Object
Set the object’s description.
115 116 117 118 119 120 121 |
# File 'lib/gamefic/describable.rb', line 115 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?
101 102 103 |
# File 'lib/gamefic/describable.rb', line 101 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.
27 28 29 |
# File 'lib/gamefic/describable.rb', line 27 def indefinitely ((proper_named? or indefinite_article == '') ? '' : "#{indefinite_article} ") + name 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.
18 19 20 |
# File 'lib/gamefic/describable.rb', line 18 def keywords Keywords.new "#{name} #{synonyms}" end |
#proper_named=(bool) ⇒ Object
Set whether the object has a proper name.
58 59 60 61 62 63 64 65 66 |
# File 'lib/gamefic/describable.rb', line 58 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.”
51 52 53 |
# File 'lib/gamefic/describable.rb', line 51 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.”
145 146 147 |
# File 'lib/gamefic/describable.rb', line 145 def to_s indefinitely end |