Class: Direction

Inherits:
Object
  • Object
show all
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.



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

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

Instance Attribute Details

#adjectiveString

Returns:

  • (String)


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

def adjective
  @adjective || @name
end

#adverbString

Returns:

  • (String)


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

def adverb
  @adverb || @name
end

#nameString

Returns:

  • (String)


5
6
7
# File 'lib/gamefic-standard/direction.rb', line 5

def name
  @name
end

#reverseObject



28
29
30
# File 'lib/gamefic-standard/direction.rb', line 28

def reverse
  Direction.find @reverse
end

Class Method Details

.compassObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gamefic-standard/direction.rb', line 37

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:



54
55
56
57
58
# File 'lib/gamefic-standard/direction.rb', line 54

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

  compass[dir.to_s.downcase.to_sym]
end

Instance Method Details

#synonymsString

Returns:

  • (String)


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

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

#to_sObject



32
33
34
# File 'lib/gamefic-standard/direction.rb', line 32

def to_s
  @name
end