Module: Gamefic::Describable

Includes:
Grammar::Person, Grammar::Plural
Included in:
Entity
Defined in:
lib/gamefic/describable.rb

Overview

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

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 Grammar::Plural

#plural?

Instance Attribute Details

#definite_articleString

Get the definite article for this object.



41
42
43
# File 'lib/gamefic/describable.rb', line 41

def definite_article
  @definite_article || "the"
end

#indefinite_articleObject

Returns the value of attribute indefinite_article.



11
12
13
# File 'lib/gamefic/describable.rb', line 11

def indefinite_article
  @indefinite_article
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/gamefic/describable.rb', line 10

def name
  @name
end

#synonymsObject

Returns the value of attribute synonyms.



11
12
13
# File 'lib/gamefic/describable.rb', line 11

def synonyms
  @synonyms
end

Class Method Details

.default_descriptionString

Get the object’s default description.



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

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



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

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.



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

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

#descriptionString

Get the object’s description.



108
109
110
# File 'lib/gamefic/describable.rb', line 108

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

#description=(text) ⇒ Object

Set the object’s description.



115
116
117
118
119
120
121
# File 'lib/gamefic/describable.rb', line 115

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?



101
102
103
# File 'lib/gamefic/describable.rb', line 101

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.



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

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

#keywordsKeywords

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



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

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

#proper_named=(bool) ⇒ Object

Set whether the object has a proper name.



58
59
60
61
62
63
64
65
66
# File 'lib/gamefic/describable.rb', line 58

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



51
52
53
# File 'lib/gamefic/describable.rb', line 51

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



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

def to_s
  indefinitely
end