Class: EVURI

Inherits:
Object show all
Defined in:
lib/rwd/net.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ EVURI

Returns a new instance of EVURI.


145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/rwd/net.rb', line 145

def initialize(url)
  begin
    @protocol, @userpass, @host, @port, d1, @path, d2, @vars, @anchor	= URI.split(url.to_s)
  rescue
  end

  @path		= "/"		if (not @path.nil? and @path.empty? and @protocol == "http")

  @protocol		= ""		if @protocol.nil?
  @userpass		= ""		if @userpass.nil?
  @host		= ""		if @host.nil?
  @port		= 0		if @port.nil?
  @path		= ""		if @path.nil?
  @vars		= ""		if @vars.nil?
  @anchor		= ""		if @anchor.nil?

  res			= {}
  @varsvolgorde	= []
  @vars.split(/&/).each{|var| k, v = var.split(/=/) ; res[k] = v ; @varsvolgorde << k}
  @vars		= res

  @port		= @port.to_i
end

Instance Attribute Details

#anchorObject

Returns the value of attribute anchor


142
143
144
# File 'lib/rwd/net.rb', line 142

def anchor
  @anchor
end

#hostObject

Returns the value of attribute host


134
135
136
# File 'lib/rwd/net.rb', line 134

def host
  @host
end

#pathObject

Returns the value of attribute path


138
139
140
# File 'lib/rwd/net.rb', line 138

def path
  @path
end

#portObject

Returns the value of attribute port


136
137
138
# File 'lib/rwd/net.rb', line 136

def port
  @port
end

#protocolObject

Returns the value of attribute protocol


130
131
132
# File 'lib/rwd/net.rb', line 130

def protocol
  @protocol
end

#userpassObject

Returns the value of attribute userpass


132
133
134
# File 'lib/rwd/net.rb', line 132

def userpass
  @userpass
end

#varsObject

Returns the value of attribute vars


140
141
142
# File 'lib/rwd/net.rb', line 140

def vars
  @vars
end

Instance Method Details

#+(url2) ⇒ Object


169
170
171
172
173
174
# File 'lib/rwd/net.rb', line 169

def +(url2)
  url1	= self.to_s
  url2	= url2.to_s	if url2.kind_of?(self.class)

  return EVURI.new((URI::Generic.new(*URI.split(url1)) + URI::Generic.new(*URI.split(url2))).to_s)	rescue nil
end

#localnameObject


202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/rwd/net.rb', line 202

def localname
  protocol	= @protocol
  userpass	= @userpass
  host	= @host
  port	= @port
  path	= @path
  vars	= varstring
  anchor	= @anchor

  protocol	= nil	if @protocol.empty?
  userpass	= nil	if @userpass.empty?
  host	= nil	if @host.empty?
  port	= nil	if @port.zero?
  path	= nil	if @path.empty?
  vars	= nil	if @vars.empty?
  anchor	= nil	if @anchor.empty?

  path	= "#{path}."	if path =~ /[\/\\]$/

  f	= MD5.new(protocol.to_s + userpass.to_s + host.to_s + port.to_s + File.dirname(path.to_s) + vars.to_s).to_s
  e	= File.basename(path.to_s).gsub(/[^\w\.\-]/, "_").gsub(/_+/, "_")
  res	= f + "." + e
  res.gsub!(/[^\w]+$/, "")

  return res
end

#to_sObject


176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/rwd/net.rb', line 176

def to_s
  protocol	= @protocol
  userpass	= @userpass
  host	= @host
  port	= @port
  path	= @path
  vars	= varstring
  anchor	= @anchor

  protocol	= nil	if @protocol.empty?
  userpass	= nil	if @userpass.empty?
  host	= nil	if @host.empty?
  port	= nil	if @port.zero?
  path	= nil	if @path.empty?
  vars	= nil	if @vars.empty?
  anchor	= nil	if @anchor.empty?

  res	= URI::HTTP.new(@protocol, @userpass, @host, port, nil, @path, nil, vars, @anchor).to_s.from_html

  res.gsub!(/@/, "")	if (@userpass.nil? or @userpass.empty?)

  res.gsub!(/\#$/, "")

  return res
end

#varstringObject


229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/rwd/net.rb', line 229

def varstring
  res		= []
  vars	= @vars.dup

  @varsvolgorde.each do |k|
    if vars.include?(k)
      v	= vars[k]
      vars.delete(k)

      res << (v.nil? ? k : "#{k}=#{v}")
    end
  end

  res.concat(vars.collect{|k, v| v.nil? ? k : "#{k}=#{v}"})

  return res.join("&")
end