Class: Alt::URI::Gen::URIParts

Inherits:
Base show all
Defined in:
lib/rio/alturi/uri_parts.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#_do_esc, #_do_unesc, #nil_or

Constructor Details

#initialize(opts = {}) ⇒ URIParts

Returns a new instance of URIParts.



273
274
275
276
# File 'lib/rio/alturi/uri_parts.rb', line 273

def initialize(opts={})
  @store = { :path => "" }
  @encoding = opts[:encoding]
end

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



272
273
274
# File 'lib/rio/alturi/uri_parts.rb', line 272

def encoding
  @encoding
end

#storeObject (readonly)

Returns the value of attribute store.



271
272
273
# File 'lib/rio/alturi/uri_parts.rb', line 271

def store
  @store
end

Class Method Details

.create(hash) ⇒ Object



296
297
298
299
300
301
302
# File 'lib/rio/alturi/uri_parts.rb', line 296

def self.create(hash)
  u = URIParts.new
  hash.each do |k,v|
    u.__send__(k.to_s+'=',v)
  end
  u
end

.parse(str, opts = {}) ⇒ Object



290
291
292
293
294
# File 'lib/rio/alturi/uri_parts.rb', line 290

def self.parse(str,opts={})
  u = URIParts.new(opts)
  u.uri = str
  u
end

Instance Method Details

#==(other) ⇒ Object



283
284
285
# File 'lib/rio/alturi/uri_parts.rb', line 283

def ==(other)
  @store == other.store
end

#[](sym) ⇒ Object



304
305
306
# File 'lib/rio/alturi/uri_parts.rb', line 304

def [](sym)
  @store[sym]
end

#[]=(sym, val) ⇒ Object



308
309
310
# File 'lib/rio/alturi/uri_parts.rb', line 308

def []=(sym,val)
  @store[sym] = val
end

#abs(base) ⇒ Object



466
467
468
# File 'lib/rio/alturi/uri_parts.rb', line 466

def abs(base)
  Alt::URI::Algorithm.transform(self,base)
end

#absolute?Boolean

Returns:

  • (Boolean)


458
459
460
# File 'lib/rio/alturi/uri_parts.rb', line 458

def absolute?
  self.scheme != nil
end

#authorityObject



339
340
341
342
# File 'lib/rio/alturi/uri_parts.rb', line 339

def authority
  #p @store
  @store[:authority].value if @store[:authority]
end

#authority=(val) ⇒ Object



344
345
346
# File 'lib/rio/alturi/uri_parts.rb', line 344

def authority=(val)
  @store[:authority] = AuthParts.parse(val) if val
end

#fragmentObject



416
417
418
# File 'lib/rio/alturi/uri_parts.rb', line 416

def fragment
  _do_unesc(@store[:fragment]) if @store[:fragment]
end

#fragment=(val) ⇒ Object



348
349
350
# File 'lib/rio/alturi/uri_parts.rb', line 348

def fragment=(val)
  @store[:fragment] = nil_or(val) { |v| _do_esc(v,:fragment) }
end

#hostObject



407
408
409
# File 'lib/rio/alturi/uri_parts.rb', line 407

def host
  @store[:authority].host if @store[:authority]
end

#host=(val) ⇒ Object



398
399
400
401
# File 'lib/rio/alturi/uri_parts.rb', line 398

def host=(val)
  @store[:authority] ||= AuthParts.new
  @store[:authority].host = nil_or(val) { |v| v.downcase }
end

#initialize_copy(other) ⇒ Object



278
279
280
281
282
# File 'lib/rio/alturi/uri_parts.rb', line 278

def initialize_copy(other)
  super
  @store = other.store.dup
  @encoding = other.encoding
end

#inspectObject



473
474
475
476
477
# File 'lib/rio/alturi/uri_parts.rb', line 473

def inspect()
  str = @store.keys.map{ |k| "#{k}:#{@store[k].inspect}" }.join(" ")
  
  sprintf '#<URIParts:0x%0x %s>',self.object_id,str
end

#netpathObject



440
441
442
# File 'lib/rio/alturi/uri_parts.rb', line 440

def netpath
  URIString.new(nil,authority,path,nil,nil).to_s
end

#netpath=(val) ⇒ Object



443
444
445
446
447
448
449
450
451
452
453
# File 'lib/rio/alturi/uri_parts.rb', line 443

def netpath=(val)
  if !val
    self.authority = nil
    self.path = ""
  else
    Alt::URI::Parse::RE_GENERIC.match(val) { |m|
      self.authority = m[2]
      self.path = m[3]
    }
  end
end

#passwordObject



330
331
332
# File 'lib/rio/alturi/uri_parts.rb', line 330

def password
  @store[:authority].password if @store[:authority]
end

#password=(val) ⇒ Object



334
335
336
337
# File 'lib/rio/alturi/uri_parts.rb', line 334

def password=(val)
  @store[:authority] ||= AuthParts.new
  @store[:authority].password = val
end

#pathObject



360
361
362
363
364
365
# File 'lib/rio/alturi/uri_parts.rb', line 360

def path
  ans = _do_unesc(@store[:path])
  #p 'HERE'
  #p ans
  ans
end

#path=(val) ⇒ Object



355
356
357
358
359
# File 'lib/rio/alturi/uri_parts.rb', line 355

def path=(val)
  @store[:path] = nil_or(val,"") { |v| 
    _do_esc(v,:path) 
  }
end

#portObject



411
412
413
# File 'lib/rio/alturi/uri_parts.rb', line 411

def port
  @store[:authority].port if @store[:authority]
end

#port=(val) ⇒ Object



393
394
395
396
# File 'lib/rio/alturi/uri_parts.rb', line 393

def port=(val)
  @store[:authority] ||= AuthParts.new
  @store[:authority].port = nil_or(val) { |v| v.to_s }
end

#queryObject



381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/rio/alturi/uri_parts.rb', line 381

def query
  if @store[:query]
    qparts = @store[:query].split('&',-1)
    if qparts.size > 1
      qparts.map { |el| _do_unesc(el) }
    elsif qparts.size == 1
      _do_unesc(qparts[0])
    else
      ""
    end
  end
end

#query=(val) ⇒ Object



368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/rio/alturi/uri_parts.rb', line 368

def query=(val)
  @store[:query] = nil_or(val) { |v|
    if v.instance_of?(::Array)  
      unless v.empty?
        v.map { |el| 
          _do_esc(el,:query_part) 
        }.join('&')
      end
    else 
      _do_esc(v,:query)
    end
  }
end

#rel(base) ⇒ Object



470
471
472
# File 'lib/rio/alturi/uri_parts.rb', line 470

def rel(base)
  Alt::URI::Algorithm.relative(self,base)
end

#relative?Boolean

Returns:

  • (Boolean)


462
463
464
# File 'lib/rio/alturi/uri_parts.rb', line 462

def relative?
  !self.absolute?
end

#schemeObject



403
404
405
# File 'lib/rio/alturi/uri_parts.rb', line 403

def scheme
  @store[:scheme]
end

#scheme=(val) ⇒ Object



352
353
354
# File 'lib/rio/alturi/uri_parts.rb', line 352

def scheme=(val)
  @store[:scheme] = nil_or(val) { |v| v.downcase }
end

#to_sObject



454
455
456
# File 'lib/rio/alturi/uri_parts.rb', line 454

def to_s
  URIString.new(@store[:scheme],authority,@store[:path],@store[:query],@store[:fragment]).to_s
end

#uriObject



420
421
422
# File 'lib/rio/alturi/uri_parts.rb', line 420

def uri
  self.to_s
end

#uri=(val) ⇒ Object



425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/rio/alturi/uri_parts.rb', line 425

def uri=(val)
  if !val
    @store.clear
    @store[:path] = ""
  else
    Alt::URI::Parse::RE_GENERIC.match(val) { |m|
      self.scheme = m[1]
      self.authority = m[2]
      @store[:path] = m[3]
      @store[:query] = m[4]
      @store[:fragment] = m[5]
    }
  end
end

#userObject



321
322
323
# File 'lib/rio/alturi/uri_parts.rb', line 321

def user
  @store[:authority].user if @store[:authority]
end

#user=(val) ⇒ Object



325
326
327
328
# File 'lib/rio/alturi/uri_parts.rb', line 325

def user=(val)
  @store[:authority] ||= AuthParts.new
  @store[:authority].user = val
end

#userinfoObject



312
313
314
# File 'lib/rio/alturi/uri_parts.rb', line 312

def userinfo
  @store[:authority].userinfo if @store[:authority]
end

#userinfo=(val) ⇒ Object



316
317
318
319
# File 'lib/rio/alturi/uri_parts.rb', line 316

def userinfo=(val)
  @store[:authority] ||= AuthParts.new
  @store[:authority].userinfo = val
end