class Direction

Attributes

adjective[W]
adverb[W]
name[RW]

@return [String]

reverse[W]

Public Class Methods

compass() click to toggle source
# File lib/gamefic-standard/direction.rb, line 39
def compass
  @compass ||= {
    north: Direction.new(name: 'north', adjective: 'northern', reverse: :south),
    south: Direction.new(name: 'south', adjective: 'southern', reverse: :north),
    west: Direction.new(name: 'west', adjective: 'western', reverse: :east),
    east: Direction.new(name: 'east', adjective: 'eastern', reverse: :west),
    northwest: Direction.new(name: 'northwest', adjective: 'northwestern', reverse: :southeast),
    southeast: Direction.new(name: 'southeast', adjective: 'southeastern', reverse: :northwest),
    northeast: Direction.new(name: 'northeast', adjective: 'northeastern', reverse: :southwest),
    southwest: Direction.new(name: 'southwest', adjective: 'southwestern', reverse: :northeast),
    up: Direction.new(name: 'up', adjective: 'upwards', reverse: :down),
    down: Direction.new(name: 'down', adjective: 'downwards', reverse: :up)
  }
end
find(dir) click to toggle source

@param dir [Direction, string] @return [Direction, nil]

# File lib/gamefic-standard/direction.rb, line 56
def find(dir)
  return dir if dir.is_a?(Direction)
  compass[dir.to_s.downcase.to_sym]
end
new(**args) click to toggle source
# File lib/gamefic-standard/direction.rb, line 9
def initialize **args
  args.each { |key, value|
    send "#{key}=", value
  }
end

Public Instance Methods

adjective() click to toggle source

@return [String]

# File lib/gamefic-standard/direction.rb, line 16
def adjective
  @adjective || @name
end
adverb() click to toggle source

@return [String]

# File lib/gamefic-standard/direction.rb, line 21
def adverb
  @adverb || @name
end
reverse() click to toggle source
# File lib/gamefic-standard/direction.rb, line 30
def reverse
  Direction.find @reverse
end
synonyms() click to toggle source

@return [String]

# File lib/gamefic-standard/direction.rb, line 26
def synonyms
  "#{adjective} #{adverb}"
end
to_s() click to toggle source
# File lib/gamefic-standard/direction.rb, line 34
def to_s
  @name
end