Method: URI::Generic.build

Defined in:
lib/extensions/uri/uri/generic.rb

.build(args) ⇒ Object

Synopsis

See #new

Description

Creates a new URI::Generic instance from components of URI::Generic with check. Components are: scheme, userinfo, host, port, registry, path, opaque, query and fragment. You can provide arguments either by an Array or a Hash. See #new for hash keys to use or for order of array items.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/extensions/uri/uri/generic.rb', line 107

def self.build(args)
  if args.kind_of?(Array) &&
      args.size == ::URI::Generic::COMPONENT.size
    tmp = args
  elsif args.kind_of?(Hash)
    tmp = ::URI::Generic::COMPONENT.collect do |c|
      if args.include?(c)
        args[c]
      else
        nil
      end
    end
  else
    raise ArgumentError, 
    "expected Array of or Hash of components of #{self.class} (#{self.class.component.join(', ')})"
  end

  tmp << nil
  tmp << true
  return self.new(*tmp)
end