class CoopAl::Path

Path

Attributes

adventure[R]
chapter[R]

Public Class Methods

absolute(adventure, chapter) click to toggle source
# File lib/coop_al/path.rb, line 25
def self.absolute(adventure, chapter)
  Path.new(adventure, chapter)
end
new(adventure, chapter) click to toggle source
# File lib/coop_al/path.rb, line 8
def initialize(adventure, chapter)
  @adventure = adventure
  @chapter = chapter
end
parse(path) click to toggle source
# File lib/coop_al/path.rb, line 37
def self.parse(path)
  tokens = path.split('/').map(&:to_sym)
  raise "Invalid path #{path}" if tokens.count > 2
  return absolute(tokens[0], tokens[1]) if tokens.count == 2
  return root if tokens[0] == :downtime
  relative(tokens[0])
end
relative(chapter) click to toggle source
# File lib/coop_al/path.rb, line 29
def self.relative(chapter)
  Path.new(nil, chapter)
end
root() click to toggle source
# File lib/coop_al/path.rb, line 33
def self.root
  Path.new(nil, nil)
end

Public Instance Methods

+(other) click to toggle source
# File lib/coop_al/path.rb, line 49
def +(other)
  local_path = other.is_a?(Path) ? other : Path.parse(other)
  return local_path if local_path.absolute?
  raise 'Cannot add two relative paths' if relative?
  Path.absolute(@adventure, other.chapter)
end
==(other) click to toggle source
# File lib/coop_al/path.rb, line 45
def ==(other)
  to_s == other.to_s
end
absolute?() click to toggle source
# File lib/coop_al/path.rb, line 21
def absolute?
  !relative?
end
adventure_s() click to toggle source
# File lib/coop_al/path.rb, line 60
def adventure_s
  return @adventure.to_s + '/' if absolute?
  ''
end
relative?() click to toggle source
# File lib/coop_al/path.rb, line 17
def relative?
  @adventure.nil? && !@chapter.nil?
end
root?() click to toggle source
# File lib/coop_al/path.rb, line 13
def root?
  @adventure.nil? && @chapter.nil?
end
to_s() click to toggle source
# File lib/coop_al/path.rb, line 56
def to_s
  adventure_s + @chapter.to_s
end