Class: CoopAl::Path
- Inherits:
-
Object
- Object
- CoopAl::Path
- Defined in:
- lib/coop_al/path.rb
Overview
Path
Instance Attribute Summary collapse
-
#adventure ⇒ Object
readonly
Returns the value of attribute adventure.
-
#chapter ⇒ Object
readonly
Returns the value of attribute chapter.
Class Method Summary collapse
- .absolute(adventure, chapter) ⇒ Object
- .parse(path) ⇒ Object
- .relative(chapter) ⇒ Object
- .root ⇒ Object
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #absolute? ⇒ Boolean
- #adventure_s ⇒ Object
-
#initialize(adventure, chapter) ⇒ Path
constructor
A new instance of Path.
- #relative? ⇒ Boolean
- #root? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#adventure ⇒ Object (readonly)
Returns the value of attribute adventure.
6 7 8 |
# File 'lib/coop_al/path.rb', line 6 def adventure @adventure end |
#chapter ⇒ Object (readonly)
Returns the value of attribute chapter.
6 7 8 |
# File 'lib/coop_al/path.rb', line 6 def chapter @chapter end |
Class Method Details
.absolute(adventure, chapter) ⇒ Object
25 26 27 |
# File 'lib/coop_al/path.rb', line 25 def self.absolute(adventure, chapter) Path.new(adventure, chapter) end |
.parse(path) ⇒ Object
37 38 39 40 41 42 43 |
# 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 |
Instance Method Details
#+(other) ⇒ Object
49 50 51 52 53 54 |
# 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) ⇒ Object
45 46 47 |
# File 'lib/coop_al/path.rb', line 45 def ==(other) to_s == other.to_s end |
#absolute? ⇒ Boolean
21 22 23 |
# File 'lib/coop_al/path.rb', line 21 def absolute? !relative? end |
#adventure_s ⇒ Object
60 61 62 63 |
# File 'lib/coop_al/path.rb', line 60 def adventure_s return @adventure.to_s + '/' if absolute? '' end |
#relative? ⇒ Boolean
17 18 19 |
# File 'lib/coop_al/path.rb', line 17 def relative? @adventure.nil? && !@chapter.nil? end |
#root? ⇒ Boolean
13 14 15 |
# File 'lib/coop_al/path.rb', line 13 def root? @adventure.nil? && @chapter.nil? end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/coop_al/path.rb', line 56 def to_s adventure_s + @chapter.to_s end |