Sha256: 072d93d477d22bc480bbf6480a398cd73f883f45749a0c06aadf4572c7bb24ad
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
class Direction attr_accessor :name, :adjective, :adverb, :reverse def initialize args = {} args.each { |key, value| send "#{key}=", value } if !reverse.nil? reverse.reverse = self end end def adjective @adjective || @name end def adverb @adverb || @name end def reverse=(dir) @reverse = dir end def synonyms "#{adjective} #{adverb}" end def to_s @name end class << self def compass if @compass.nil? @compass = {} @compass[:north] = Direction.new(:name => 'north', :adjective => 'northern') @compass[:south] = Direction.new(:name => 'south', :adjective => 'southern', :reverse => @compass[:north]) @compass[:west] = Direction.new(:name => 'west', :adjective => 'western') @compass[:east] = Direction.new(:name => 'east', :adjective => 'eastern', :reverse => @compass[:west]) @compass[:northwest] = Direction.new(:name => 'northwest', :adjective => 'northwestern') @compass[:southeast] = Direction.new(:name => 'southeast', :adjective => 'southeastern', :reverse => @compass[:northwest]) @compass[:northeast] = Direction.new(:name => 'northeast', :adjective => 'northeastern') @compass[:southwest] = Direction.new(:name => 'southwest', :adjective => 'southwestern', :reverse => @compass[:northeast]) @compass[:up] = Direction.new(:name => 'up', :adjective => 'upwards') @compass[:down] = Direction.new(:name => 'down', :adjective => 'downwards', :reverse => @compass[:up]) end @compass end def find(dir) compass[dir.to_s.downcase.to_sym] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gamefic-standard-2.0.0 | lib/gamefic-standard/direction.rb |