Class: Vpim::Agent::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/vpim/agent/calendars.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, base = "") ⇒ Path

URI is the uri being queried, base is where this path is mounted under?



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vpim/agent/calendars.rb', line 36

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



26
27
28
29
30
31
32
33
# File 'lib/vpim/agent/calendars.rb', line 26

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



64
65
66
67
68
69
70
71
# File 'lib/vpim/agent/calendars.rb', line 64

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



73
74
75
76
# File 'lib/vpim/agent/calendars.rb', line 73

def prefix(len = nil)
  len ||= @mark
  @path[0, len].map{|p| CGI.escape(p)}.join("/") + "/"
end

#shiftObject

TODO - call this #next



58
59
60
61
62
# File 'lib/vpim/agent/calendars.rb', line 58

def shift
  if @path[@mark]
    @path[@mark += 1]
  end
end

#to_pathObject



53
54
55
# File 'lib/vpim/agent/calendars.rb', line 53

def to_path
  self
end

#uriObject



49
50
51
# File 'lib/vpim/agent/calendars.rb', line 49

def uri
  @uri.to_s
end