Class: Direction

Inherits:
Object
  • Object
show all
Includes:
Gamefic::Serialize
Defined in:
lib/gamefic-standard/direction.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Direction

Returns a new instance of Direction.



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

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

Instance Attribute Details

#adjectiveString

Returns:

  • (String)


16
17
18
# File 'lib/gamefic-standard/direction.rb', line 16

def adjective
  @adjective || @name
end

#adverbString

Returns:

  • (String)


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

def adverb
  @adverb || @name
end

#nameString

Returns:

  • (String)


7
8
9
# File 'lib/gamefic-standard/direction.rb', line 7

def name
  @name
end

#reverseObject



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

def reverse
  Direction.find @reverse
end

Class Method Details

.compassObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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) ⇒ Direction?

Parameters:

Returns:



56
57
58
59
# 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

Instance Method Details

#synonymsString

Returns:

  • (String)


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

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

#to_sObject



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

def to_s
  @name
end