module Gamefic::Describable

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

Attributes

definite_article[W]

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

@return [String]

indefinite_article[RW]

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

@return [String]

name[R]

The object’s name. Names are 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 reference the object. Synonyms are used in conjunction with the object’s name when scanning tokens.

@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 152
def self.default_description
  @default_description || "There's nothing special about %<name>s."
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 145
def self.default_description=(text)
  @default_description = text
end

Public Instance Methods

definite_article() click to toggle source

Tefinite article for this object (usually “the”).

@return [String]

# File lib/gamefic/describable.rb, line 57
def definite_article
  @definite_article || "the"
end
definitely() click to toggle source

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 50
def definitely
  (proper_named? || definite_article == '' ? '' : "#{definite_article} ") + name.to_s
end
described?() click to toggle source

Does the object have a description?

@return [Boolean]

# File lib/gamefic/describable.rb, line 115
def described?
  @description.to_s != ''
end
Also aliased as: description?, has_description?
description() click to toggle source

Get the object’s description.

@return [String]

# File lib/gamefic/describable.rb, line 124
def description
  @description || format(Describable.default_description, name: definitely, Name: definitely.capitalize_first)
end
description=(text) click to toggle source

Set the object’s description.

@param text [String]

# File lib/gamefic/describable.rb, line 131
def description=(text)
  @description = (text if text != (format(Describable.default_description, name: definitely, Name: definitely.capitalize_first)))
end
description?()
Alias for: described?
has_description?()
Alias for: described?
indefinitely() click to toggle source

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 41
def indefinitely
  (proper_named? || indefinite_article == '' ? '' : "#{indefinite_article} ") + name.to_s
end
keywords() click to toggle source
# File lib/gamefic/describable.rb, line 32
def keywords
  "#{name} #{synonyms}".keywords
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 87
def name=(value)
  words = value.split
  if %w[a an].include?(words[0].downcase)
    @indefinite_article = words[0].downcase
    @definite_article = 'the'
    value = value[words[0].length + 1..].strip
  else
    if words[0].downcase == 'the'
      if proper_named?
        @definite_article = nil
      else
        @definite_article = 'the'
        value = value[4..].strip
      end
    end
    # Try to guess the indefinite article
    @indefinite_article = if %w[a e i o u].include?(value[0, 1].downcase)
                            'an'
                          else
                            '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 74
def proper_named=(bool)
  if bool && @definite_article
    @name = "#{@definite_article} #{@name}".strip
    @definite_article = nil
  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 67
def proper_named?
  @proper_named == true
end
synonyms=(text) click to toggle source
# File lib/gamefic/describable.rb, line 135
def synonyms= text
  @synonyms = text
end
to_s() click to toggle source

Get a String representation of the object. By default, this is either the object’s name with an indefinite article, e.g., “a person” or “a red dog”; or its proper name, e.g., “Mr. Smith”.

@return [String]

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