Class: Vpim::Agent::Path
- Inherits:
-
Object
- Object
- Vpim::Agent::Path
- Defined in:
- lib/vpim/agent/calendars.rb
Class Method Summary collapse
Instance Method Summary collapse
- #append(name, scheme = nil) ⇒ Object
-
#initialize(uri, base = "") ⇒ Path
constructor
URI is the uri being queried, base is where this path is mounted under?.
- #prefix(len = nil) ⇒ Object
-
#shift ⇒ Object
TODO - call this #next.
- #to_path ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(uri, base = "") ⇒ Path
URI is the uri being queried, base is where this path is mounted under?
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vpim/agent/calendars.rb', line 37 def initialize(uri, base = "") @uri = URI.parse(uri.to_s) #pp [uri, base, @uri] if @uri.path.size == 0 @uri.path = "/" end @path = Path.split_path(@uri.path) @base = base.to_str @mark = 0 @base.split.size.times{ shift } end |
Class Method Details
.split_path(path) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/vpim/agent/calendars.rb', line 27 def self.split_path(path) begin path = path.to_ary rescue NameError path = path.split("/") end path.map{|w| CGI.unescape(w)} end |
Instance Method Details
#append(name, scheme = nil) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/vpim/agent/calendars.rb', line 65 def append(name, scheme = nil) uri = @uri.dup uri.path += "/" + CGI.escape(name) if scheme uri.scheme = scheme end uri end |
#prefix(len = nil) ⇒ Object
74 75 76 77 |
# File 'lib/vpim/agent/calendars.rb', line 74 def prefix(len = nil) len ||= @mark @path[0, len].map{|p| CGI.escape(p)}.join("/") + "/" end |
#shift ⇒ Object
TODO - call this #next
59 60 61 62 63 |
# File 'lib/vpim/agent/calendars.rb', line 59 def shift if @path[@mark] @path[@mark += 1] end end |
#to_path ⇒ Object
54 55 56 |
# File 'lib/vpim/agent/calendars.rb', line 54 def to_path self end |
#uri ⇒ Object
50 51 52 |
# File 'lib/vpim/agent/calendars.rb', line 50 def uri @uri.to_s end |