module Gamefic::Describable
A variety of text properties for naming, describing, and referencing objects.
Attributes
The object’s definite article (usually “the”).
@return [String]
The object’s indefinite article (usually “a” or “an”).
@return [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”).
@return [String]
@return [String]
Alternate words that can reference the object. Synonyms are used in conjunction with the object’s name when scanning tokens.
@return [String]
Public Class Methods
Source
# File lib/gamefic/describable.rb, line 165 def self.default_description @default_description || "There's nothing special about %<name>s." end
Get the object’s default description.
@return [String]
Source
# File lib/gamefic/describable.rb, line 158 def self.default_description=(text) @default_description = text end
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
@param text [String]
Public Instance Methods
Source
# File lib/gamefic/describable.rb, line 70 def definite_article @definite_article || "the" end
Tefinite article for this object (usually “the”).
@return [String]
Source
# File lib/gamefic/describable.rb, line 63 def definitely (proper_named? || definite_article == '' ? '' : "#{definite_article} ") + name.to_s end
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.
@return [String]
Source
# File lib/gamefic/describable.rb, line 128 def described? @description.to_s != '' end
Does the object have a description?
@return [Boolean]
Source
# File lib/gamefic/describable.rb, line 137 def description @description || format(Describable.default_description, name: definitely, Name: definitely.capitalize_first) end
Get the object’s description.
@return [String]
Source
# 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
Set the object’s description.
@param text [String]
Source
# File lib/gamefic/describable.rb, line 54 def indefinitely (proper_named? || indefinite_article == '' ? '' : "#{indefinite_article} ") + name.to_s end
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.
@return [String]
Source
# File lib/gamefic/describable.rb, line 35 def keywords "#{name} #{synonyms}".keywords end
Source
# File lib/gamefic/describable.rb, line 100 def name=(value) words = value.split if %w[a an].include?(words[0].downcase) @indefinite_article = words[0].downcase @definite_article = 'the' value = value[words[0].length + 1..].strip else if words[0].downcase == 'the' if proper_named? @definite_article = nil else @definite_article = 'the' value = value[4..].strip end end # Try to guess the indefinite article @indefinite_article = if %w[a e i o u].include?(value[0, 1].downcase) 'an' else 'a' end end @name = value end
Set the name of the object. Setting the name performs some magic to determine how to handle articles (“an object” and “the object”).
@param value [String]
Source
# File lib/gamefic/describable.rb, line 45 def nuance @nuance ||= '' end
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.
@return [String]
Source
# 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
Set whether the object has a proper name.
@param bool [Boolean]
Source
# File lib/gamefic/describable.rb, line 80 def proper_named? @proper_named == true end
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.”
@return [Boolean]
Source
# File lib/gamefic/describable.rb, line 148 def synonyms= text @synonyms = text end