module Gamefic::Describable

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

Attributes

definite_article[R]

The object's definite article (usually “the”).

@return [String]

indefinite_article[R]

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

@return [String]

name[R]

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

@return [String]

synonyms[R]

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

@return [String]

Public Class Methods

default_description() click to toggle source

Get the object's default description.

@return [String]

# File lib/gamefic/describable.rb, line 177
def self.default_description
  @default_description || "There's nothing special about %{name}."
end
default_description=(text) click to toggle source

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

@param text [String]

# File lib/gamefic/describable.rb, line 170
def self.default_description=(text)
  @default_description = text
end

Public Instance Methods

definite_article=(article) click to toggle source

Set the definite article.

@param [String] article

# File lib/gamefic/describable.rb, line 67
def definite_article= article
  @keywords = nil
  @definite_article = article
end
definitely() click to toggle source

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.

@return [String]

# File lib/gamefic/describable.rb, line 53
def definitely
  ((proper_named? or definite_article == '') ? '' : "#{definite_article} ") + name.to_s
end
description() click to toggle source

Get the object's description.

@return [String]

# File lib/gamefic/describable.rb, line 144
def description
  @description || (Describable.default_description % { :name => self.definitely, :Name => self.definitely.capitalize_first })
end
description=(text) click to toggle source

Set the object's description.

@param text [String]

# 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?() click to toggle source

Does the object have a description?

@return [Boolean]

# File lib/gamefic/describable.rb, line 137
def has_description?
  (@description.to_s != '')
end
indefinite_article=(article) click to toggle source

Set the indefinite article.

@param [String] article

# File lib/gamefic/describable.rb, line 75
def indefinite_article= article
  @keywords = nil
  @indefinite_article = article
end
indefinitely() click to toggle source

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.

@return [String]

# File lib/gamefic/describable.rb, line 44
def indefinitely
  ((proper_named? or indefinite_article == '') ? '' : "#{indefinite_article} ") + name.to_s
end
keywords() click to toggle source

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

@return [Array<String>]

# File lib/gamefic/describable.rb, line 35
def keywords
  @keywords ||= "#{definite_article} #{indefinite_article} #{name} #{synonyms}".downcase.split(Keywords::SPLIT_REGEXP).uniq
end
name=(value) click to toggle source

Set the name of the object. Setting the name performs some magic to determine how to handle articles (“an object” and “the object”).

@param value [String]

# File lib/gamefic/describable.rb, line 108
def name=(value)
  @keywords = nil
  words = value.split_words
  if ['a','an'].include?(words[0].downcase)
    @indefinite_article = words[0].downcase
    @definite_article = 'the'
    value = value[words[0].length+1..-1].strip
  else
    if words[0].downcase == 'the'
      if proper_named?
        @definite_article = nil
      else
        @definite_article = 'the'
        value = value[4..-1].strip
      end
    end
    # Try to guess the indefinite article
    if ['a','e','i','o','u'].include?(value[0,1].downcase)
      @indefinite_article = 'an'
    else
      @indefinite_article = 'a'
    end
  end
  @name = value
end
proper_named=(bool) click to toggle source

Set whether the object has a proper name.

@param bool [Boolean]

# 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?() click to toggle source

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

@return [Boolean]

# File lib/gamefic/describable.rb, line 86
def proper_named?
  (@proper_named == true)
end
synonyms=(text) click to toggle source
# File lib/gamefic/describable.rb, line 159
def synonyms= text
  @keywords = nil
  @synonyms = text
end
to_s() click to toggle source

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

@return [String]

# File lib/gamefic/describable.rb, line 186
def to_s
  indefinitely
end