Module: Gamefic::Describable

Includes:
Grammar::Person, Grammar::Plural, Matchable
Included in:
Entity
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.

Returns:



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

def definite_article
  @definite_article
end

#indefinite_articleString

Returns:



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

def indefinite_article
  @indefinite_article
end

#nameString

Returns:



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

def name
  @name
end

#synonymsString

Returns:



16
17
18
# File 'lib/gamefic/describable.rb', line 16

def synonyms
  @synonyms
end

Class Method Details

.default_descriptionString

Get the object’s default description.

Returns:



162
163
164
# File 'lib/gamefic/describable.rb', line 162

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:



155
156
157
# File 'lib/gamefic/describable.rb', line 155

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

Instance Method Details

#definitelyObject

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.



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

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

#descriptionString

Get the object’s description.

Returns:



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

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

#description=(text) ⇒ Object

Set the object’s description.

Parameters:



136
137
138
139
140
141
142
# File 'lib/gamefic/describable.rb', line 136

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)


122
123
124
# File 'lib/gamefic/describable.rb', line 122

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:



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

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)


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

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)


78
79
80
81
82
83
84
85
86
# File 'lib/gamefic/describable.rb', line 78

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)


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

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:



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

def to_s
  indefinitely
end