Class: RIO::URIRef
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(u, b = nil) ⇒ URIRef
Returns a new instance of URIRef.
8
9
10
11
12
13
|
# File 'lib/rio/uriref.rb', line 8
def initialize(u,b=nil)
@ref = u
@base = b
raise ArgumentError, "Either uri(#{u}) or base(#{b.inspect}) must be absolute" unless
@ref.absolute? or @base.absolute?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
116
117
118
|
# File 'lib/rio/uriref.rb', line 116
def method_missing(sym,*args,&block)
ref.__send__(sym,*args,&block)
end
|
Instance Attribute Details
Returns the value of attribute ref.
7
8
9
|
# File 'lib/rio/uriref.rb', line 7
def ref
@ref
end
|
Class Method Details
.base_from_uref(uref) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/rio/uriref.rb', line 49
def self.base_from_uref(uref)
buri = ::Alt::URI::Gen::URIParts.new
buri.scheme = 'file'
if uref.authority
buri.authority = uref.authority
buri.path = uref.path
elsif uref.path.start_with?("/") or uref.path =~ %r{^[a-zA-Z]:}
buri.path = uref.path
buri.authority = ""
else
buri.path = ::Dir.getwd + "/"
buri.authority = ""
end
::Alt::URI::File.new(buri)
end
|
.base_str_to_uri(pth) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/rio/uriref.rb', line 78
def self.base_str_to_uri(pth)
case
when pth.start_with?("//")
::Alt::URI.create(:scheme => 'file', :netpath => pth)
when (pth.start_with?("/") or (pth =~ %r{^[a-zA-Z]:}))
::Alt::URI.create(:scheme => 'file', :authority => "", :path => pth)
when (pth =~ %r{^[a-zA-Z0-9-][a-zA-Z0-9-]+:})
::Alt::URI.parse(pth)
else
raise ArgumentError, "Base(#{pth.inspect}) must be absolute"
end
end
|
.build(u, opts = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/rio/uriref.rb', line 20
def self.build(u,opts={})
b = opts[:base]
uref = case u
when ::Alt::URI::Base then u
when ::RIO::URIRef then u.ref
else path_str_to_uri(u.to_s,opts)
end
ubase = case b
when nil
uref.absolute? ? uref : base_from_uref(uref)
else
calc_base(b)
end
new(uref,ubase)
end
|
.calc_base(b) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/rio/uriref.rb', line 38
def self.calc_base(b)
case b
when ::Alt::URI::Base
b
else
base_str_to_uri(b.to_s)
end
end
|
.path_str_to_uri(pth, opts = {}) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/rio/uriref.rb', line 65
def self.path_str_to_uri(pth,opts={})
cr_args = opts[:encoding] ? {:encoding => opts[:encoding]} : {}
case
when pth.start_with?("//")
::Alt::URI.create(cr_args.merge(:netpath => pth))
when (pth.start_with?("/") or (pth =~ %r{^[a-zA-Z]:}))
::Alt::URI.create(cr_args.merge(:path => pth))
when pth =~ %r{^[a-zA-Z][a-zA-Z]+:}
::Alt::URI.parse(pth,opts)
else
::Alt::URI.create(cr_args.merge(:path => pth))
end
end
|
Instance Method Details
#==(other) ⇒ Object
19
|
# File 'lib/rio/uriref.rb', line 19
def ==(other) ref == other.ref end
|
#abs(b = nil) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/rio/uriref.rb', line 90
def abs(b=nil)
if b.nil?
self.class.build(ref.abs(base),:base => base)
else
self.class.build(ref,:base => b).abs
end
end
|
35
36
37
|
# File 'lib/rio/uriref.rb', line 35
def base
@base
end
|
#base=(other) ⇒ Object
46
47
48
|
# File 'lib/rio/uriref.rb', line 46
def base=(other)
self.class.calc_base(other)
end
|
#initialize_copy(other) ⇒ Object
14
15
16
17
18
|
# File 'lib/rio/uriref.rb', line 14
def initialize_copy(other)
super
@ref = other.ref.clone
@base = other.base.clone
end
|
120
121
122
|
# File 'lib/rio/uriref.rb', line 120
def inspect()
sprintf '#<URIRef:0x%0x @ref="%s" @base="%s">',self.object_id,@ref.to_s,@base.to_s
end
|
#join(*args) ⇒ Object
110
111
112
113
|
# File 'lib/rio/uriref.rb', line 110
def join(*args)
ref.join(*args)
self
end
|
#rel(b = nil) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/rio/uriref.rb', line 97
def rel(b=nil)
if b.nil?
self.class.build(ref.rel(base),:base => base)
else
self.class.build(ref,:base => b).rel
end
end
|
#route_from(b) ⇒ Object
104
105
106
|
# File 'lib/rio/uriref.rb', line 104
def route_from(b)
self.class.build(abs.ref.route_from(b.ref),:base => b)
end
|
#route_to(b) ⇒ Object
107
108
109
|
# File 'lib/rio/uriref.rb', line 107
def route_to(b)
self.class.build(self.abs.ref.route_to(b.ref),:base => self.ref)
end
|
114
|
# File 'lib/rio/uriref.rb', line 114
def to_s() ref.to_s end
|