Class: Gamefic::Standard::Direction

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/standard/direction.rb

Overview

Descriptions of the geographical relationships between entities. Portals can use directions to identify the path to their destination, such as north, southwest, up, etc.

Constant Summary collapse

NORTH =
compass[:north]
SOUTH =
compass[:south]
WEST =
compass[:west]
EAST =
compass[:east]
NORTHWEST =
compass[:northwest]
SOUTHEAST =
compass[:southeast]
NORTHEAST =
compass[:northeast]
SOUTHWEST =
compass[:southwest]
UP =
compass[:up]
DOWN =
compass[:down]
IN =
compass[:in]
OUT =
compass[:out]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Direction

Returns a new instance of Direction.



13
14
15
16
17
# File 'lib/gamefic/standard/direction.rb', line 13

def initialize **args
  args.each { |key, value|
    send "#{key}=", value
  }
end

Instance Attribute Details

#adjectiveString

Returns:

  • (String)


20
21
22
# File 'lib/gamefic/standard/direction.rb', line 20

def adjective
  @adjective || @name
end

#adverbString

Returns:

  • (String)


25
26
27
# File 'lib/gamefic/standard/direction.rb', line 25

def adverb
  @adverb || @name
end

#nameString

Returns:

  • (String)


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

def name
  @name
end

#reverseObject



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

def reverse
  Direction.find @reverse
end

Class Method Details

.compassHash{Symbol => Direction}

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gamefic/standard/direction.rb', line 44

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),
    in: Direction.new(name: 'in', adjective: 'inside', reverse: :out),
    out: Direction.new(name: 'in', adjective: 'inside', reverse: :in)
  }
end

.find(dir) ⇒ Direction?

Parameters:

Returns:



67
68
69
70
71
# File 'lib/gamefic/standard/direction.rb', line 67

def find(dir)
  return dir if dir.is_a?(Direction)

  compass[dir.to_s.downcase.to_sym]
end

.namesObject



61
62
63
# File 'lib/gamefic/standard/direction.rb', line 61

def names
  compass.values.map(&:name)
end

Instance Method Details

#synonymsString

Returns:

  • (String)


30
31
32
# File 'lib/gamefic/standard/direction.rb', line 30

def synonyms
  "#{adjective} #{adverb}"
end

#to_sObject



38
39
40
# File 'lib/gamefic/standard/direction.rb', line 38

def to_s
  @name
end