Module: Gamefic::Describable

Includes:
Grammar::Person, Grammar::Plural, Matchable
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 Matchable

Matchable::SPLIT_REGEXP

Instance Attribute Summary collapse

Attributes included from Grammar::Person

#person

Attributes included from Grammar::Plural

#plural

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Matchable

#match?

Methods included from Grammar::Plural

#plural?

Instance Attribute Details

#definite_articleString

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

Returns:



31
32
33
# File 'lib/gamefic/describable.rb', line 31

def definite_article
  @definite_article
end

#indefinite_articleString

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

Returns:



26
27
28
# File 'lib/gamefic/describable.rb', line 26

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:



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

def name
  @name
end

#synonymsString

Returns:



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

def synonyms
  @synonyms
end

Class Method Details

.default_descriptionString

Get the object’s default description.

Returns:



179
180
181
# File 'lib/gamefic/describable.rb', line 179

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:



172
173
174
# File 'lib/gamefic/describable.rb', line 172

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:



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

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

#descriptionString

Get the object’s description.

Returns:



146
147
148
# File 'lib/gamefic/describable.rb', line 146

def description
  @description || (Describable.default_description % { :name => self.definitely, :Name => self.definitely.capitalize_first })
end

#description=(text) ⇒ Object

Set the object’s description.

Parameters:



153
154
155
156
157
158
159
# File 'lib/gamefic/describable.rb', line 153

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)


139
140
141
# File 'lib/gamefic/describable.rb', line 139

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:



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

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

#keywordsKeywords

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

Returns:

  • (Keywords)


37
38
39
# File 'lib/gamefic/describable.rb', line 37

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.

Parameters:

  • bool (Boolean)


95
96
97
98
99
100
101
102
103
# File 'lib/gamefic/describable.rb', line 95

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)


88
89
90
# File 'lib/gamefic/describable.rb', line 88

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:



188
189
190
# File 'lib/gamefic/describable.rb', line 188

def to_s
  indefinitely
end