Module: Gamefic::Describable

Includes:
Keywords
Included in:
Element
Defined in:
lib/gamefic/describable.rb

Overview

Add a variety of text properties for naming, describing, and referencing objects.

Constant Summary

Constants included from Keywords

Keywords::SPLIT_REGEXP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Keywords

#specified?

Instance Attribute Details

#definite_articleString

Get the definite article for this object (usually “the”).

Returns:



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

def definite_article
  @definite_article
end

#indefinite_articleString

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

Returns:



24
25
26
# File 'lib/gamefic/describable.rb', line 24

def indefinite_article
  @indefinite_article
end

#nameString

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

Returns:



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

def name
  @name
end

#synonymsString

Alternate words that can be used to describe the object. Synonyms are used in conjunction with the object’s name when generating keywords.

Returns:



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

def synonyms
  @synonyms
end

Class Method Details

.default_descriptionString

Get the object’s default description.

Returns:



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

Parameters:



170
171
172
# File 'lib/gamefic/describable.rb', line 170

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

Instance Method Details

#definitelyString

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.

Returns:



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

def definitely
  ((proper_named? or definite_article == '') ? '' : "#{definite_article} ") + name.to_s
end

#descriptionString

Get the object’s description.

Returns:



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.

Parameters:



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?

Returns:

  • (Boolean)


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

def has_description?
  (@description.to_s != '')
end

#indefinitelyString

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.

Returns:



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

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

#keywordsArray<String>

Get a set of keywords associated with the object. Keywords are typically the words in the object’s name plus its synonyms.

Returns:



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.

Parameters:

  • bool (Boolean)


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

Returns:

  • (Boolean)


86
87
88
# File 'lib/gamefic/describable.rb', line 86

def proper_named?
  (@proper_named == true)
end

#to_sString

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

Returns:



186
187
188
# File 'lib/gamefic/describable.rb', line 186

def to_s
  indefinitely
end