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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#definite_articleString

Tefinite article for this object (usually “the”).

Returns:



70
71
72
# File 'lib/gamefic/describable.rb', line 70

def definite_article
  @definite_article || "the"
end

#indefinite_articleString

The object’s indefinite article (usually “a” or “an”).

Returns:



28
29
30
# File 'lib/gamefic/describable.rb', line 28

def indefinite_article
  @indefinite_article
end

#nameString

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”).

Returns:



14
15
16
# File 'lib/gamefic/describable.rb', line 14

def name
  @name
end

#nuanceString

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.

Returns:



45
46
47
# File 'lib/gamefic/describable.rb', line 45

def nuance
  @nuance ||= ''
end

#synonymsString

Alternate words that can reference the object. Synonyms are used in conjunction with the object’s name when scanning tokens.

Returns:



20
21
22
# File 'lib/gamefic/describable.rb', line 20

def synonyms
  @synonyms
end

Class Method Details

.default_descriptionString

Get the object’s default description.

Returns:



165
166
167
# File 'lib/gamefic/describable.rb', line 165

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

Parameters:



158
159
160
# File 'lib/gamefic/describable.rb', line 158

def self.default_description=(text)
  @default_description = text
end

Instance Method Details

#definitelyString

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.

Returns:



63
64
65
# File 'lib/gamefic/describable.rb', line 63

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?

Returns:

  • (Boolean)


128
129
130
# File 'lib/gamefic/describable.rb', line 128

def described?
  @description.to_s != ''
end

#descriptionString

Get the object’s description.

Returns:



137
138
139
# File 'lib/gamefic/describable.rb', line 137

def description
  @description || format(Describable.default_description, name: definitely, Name: definitely.capitalize_first)
end

#description=(text) ⇒ Object

Set the object’s description.

Parameters:



144
145
146
# 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

#indefinitelyString

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.

Returns:



54
55
56
# File 'lib/gamefic/describable.rb', line 54

def indefinitely
  (proper_named? || indefinite_article == '' ? '' : "#{indefinite_article} ") + name.to_s
end

#keywordsObject



35
36
37
# File 'lib/gamefic/describable.rb', line 35

def keywords
  "#{name} #{synonyms}".keywords
end

#proper_named=(bool) ⇒ Object

Set whether the object has a proper name.

Parameters:

  • bool (Boolean)


87
88
89
90
91
92
93
# 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

#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.”

Returns:

  • (Boolean)


80
81
82
# File 'lib/gamefic/describable.rb', line 80

def proper_named?
  @proper_named == true
end

#to_sString

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”.

Returns:



174
175
176
# File 'lib/gamefic/describable.rb', line 174

def to_s
  indefinitely
end