Class: DataMetaParse::Uri
- Inherits:
-
Object
- Object
- DataMetaParse::Uri
- Defined in:
- lib/dataMetaParse/uriDataMeta.rb
Overview
DataMeta URI with all the parts.
The user story:
-
DataMeta URIs are used in DataMeta Scripts to specify all aspects of a data set identity and location.
-
For physical access, a URI may be disassembled using this grammar and parser, the parts obtained so may be used to access concrete physical resources.
Instance Attribute Summary collapse
-
#host ⇒ String
readonly
The host part of the URI.
-
#path ⇒ String
readonly
For the
file
protocol, path as specified, full or relative. -
#port ⇒ Fixnum
readonly
The port number specified in the URI, can be
nil
. -
#props ⇒ Hash
readonly
Hash of properties keyed by the property name and pointing to a value if any.
-
#proto ⇒ String
readonly
The protocol part, such as
http
,ftp
,socparc
etc. -
#pwd ⇒ String
readonly
The password part of the URI, can be
nil
and for some URIs may be in properties. -
#user ⇒ String
readonly
The user id part of the URI, can be
nil
and for some URIs may be in properties.
Class Method Summary collapse
-
.loadRulz ⇒ Object
Loads the grammar - has to be done only once per RVM start.
-
.parse(source) ⇒ Object
Parses the source into the instance of the object.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Equality to the other.
-
#eql?(other) ⇒ Boolean
Same as the #==.
-
#initialize(proto, user, pwd, host, port, path, props) ⇒ Uri
constructor
Creates an instance of the object.
-
#to_s ⇒ Object
Instance to textual.
Constructor Details
#initialize(proto, user, pwd, host, port, path, props) ⇒ Uri
Creates an instance of the object.
54 55 56 57 58 59 60 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 54 def initialize(proto, user, pwd, host, port, path, props) raise ArgumentError, 'Password specified but user not' if !user && pwd raise ArgumentError, 'For file protocol, only path can be specified' if proto == 'file' && ( user || pwd || host || port || !props.empty?) @proto, @user, @pwd, @host, @port, @path, @props = proto, user, pwd, host, port, path, props end |
Instance Attribute Details
#host ⇒ String (readonly)
Returns the host part of the URI.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 40 class Uri attr_reader :proto, :user, :pwd, :host, :port, :path, :props =begin rdoc Creates an instance of the object. @param [String] proto see the property {#proto} @param [String] user see the property {#user} @param [String] pwd see the property {#pwd} @param [String] host see the property {#host} @param [String] port see the property {#port} @param [String] path see the property {#path} @param [String] props see the property {#props} =end def initialize(proto, user, pwd, host, port, path, props) raise ArgumentError, 'Password specified but user not' if !user && pwd raise ArgumentError, 'For file protocol, only path can be specified' if proto == 'file' && ( user || pwd || host || port || !props.empty?) @proto, @user, @pwd, @host, @port, @path, @props = proto, user, pwd, host, port, path, props end =begin rdoc Equality to the other =end def ==(other) @proto == other.proto && @user == other.user && @pwd == other.pwd && @host == other.host && @port == other.port && @path == other.path && @props.eql?(other.props) end =begin rdoc Same as the {#==} =end def eql?(other); self == other end =begin rdoc Loads the grammar - has to be done only once per RVM start. Relies on loading the basics. =end def self.loadRulz Treetop.load(File.join(File.dirname(__FILE__), 'urlDataMeta')) end =begin rdoc Instance to textual. =end def to_s if @proto == 'file' "file://#{@path}" else result = '' result << @proto << '://' result << URI.encode_www_form_component(@user) if @user result << ':' << URI.encode_www_form_component(@pwd) if @user && @pwd result << '@' if @user result << @host result << ':' << @port.to_s if @port result << '/' if @path || !@props.empty? result << @path if @path result << '?' << @props.keys.map { |k| v=@props[k]; v ? "#{k}=#{URI.encode_www_form_component(v)}" : "#{k}" }.join('&') unless @props.empty? result end end =begin rdoc Parses the source into the instance of the object. @param [String] source the source, the URI specification to parse into the instance of this class =end def self.parse(source) fileSignature = 'file://' if source.start_with?(fileSignature) Uri.new('file', nil, nil, nil, nil, source[fileSignature.length..-1], {}) else parser = DataMetaUrlParser.new ast = parser.parse(source) return nil unless ast proto = ast.proto.text_value user = ast.user? ? ast.userPwd.user.text_value : nil pwd = ast.pwd? ? URI.decode_www_form_component(ast.userPwd.password) : nil host = ast.host.text_value port = ast.port? ? ast.port.number : nil path = ast.path? ? ast.uTail.path : nil query = ast.query? ? ast.uTail.query : nil props = {} if query pairs = query.split('&') pairs.each { |pairString| key, val = pairString.split('=') props[key] = val ? URI.decode_www_form_component(val) : nil # this is caused by ¶mA¶mB=b, in which case paramA will be nil } end Uri.new(proto, user, pwd, host, port, path, props) end end end |
#path ⇒ String (readonly)
Returns for the file
protocol, path as specified, full or relative. For any other URI, the part between the closing ‘/’ after the host:port
part and the query part starting with ‘?’. This means, for all other protocols except file
, the path part will never have an initial slash.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 40 class Uri attr_reader :proto, :user, :pwd, :host, :port, :path, :props =begin rdoc Creates an instance of the object. @param [String] proto see the property {#proto} @param [String] user see the property {#user} @param [String] pwd see the property {#pwd} @param [String] host see the property {#host} @param [String] port see the property {#port} @param [String] path see the property {#path} @param [String] props see the property {#props} =end def initialize(proto, user, pwd, host, port, path, props) raise ArgumentError, 'Password specified but user not' if !user && pwd raise ArgumentError, 'For file protocol, only path can be specified' if proto == 'file' && ( user || pwd || host || port || !props.empty?) @proto, @user, @pwd, @host, @port, @path, @props = proto, user, pwd, host, port, path, props end =begin rdoc Equality to the other =end def ==(other) @proto == other.proto && @user == other.user && @pwd == other.pwd && @host == other.host && @port == other.port && @path == other.path && @props.eql?(other.props) end =begin rdoc Same as the {#==} =end def eql?(other); self == other end =begin rdoc Loads the grammar - has to be done only once per RVM start. Relies on loading the basics. =end def self.loadRulz Treetop.load(File.join(File.dirname(__FILE__), 'urlDataMeta')) end =begin rdoc Instance to textual. =end def to_s if @proto == 'file' "file://#{@path}" else result = '' result << @proto << '://' result << URI.encode_www_form_component(@user) if @user result << ':' << URI.encode_www_form_component(@pwd) if @user && @pwd result << '@' if @user result << @host result << ':' << @port.to_s if @port result << '/' if @path || !@props.empty? result << @path if @path result << '?' << @props.keys.map { |k| v=@props[k]; v ? "#{k}=#{URI.encode_www_form_component(v)}" : "#{k}" }.join('&') unless @props.empty? result end end =begin rdoc Parses the source into the instance of the object. @param [String] source the source, the URI specification to parse into the instance of this class =end def self.parse(source) fileSignature = 'file://' if source.start_with?(fileSignature) Uri.new('file', nil, nil, nil, nil, source[fileSignature.length..-1], {}) else parser = DataMetaUrlParser.new ast = parser.parse(source) return nil unless ast proto = ast.proto.text_value user = ast.user? ? ast.userPwd.user.text_value : nil pwd = ast.pwd? ? URI.decode_www_form_component(ast.userPwd.password) : nil host = ast.host.text_value port = ast.port? ? ast.port.number : nil path = ast.path? ? ast.uTail.path : nil query = ast.query? ? ast.uTail.query : nil props = {} if query pairs = query.split('&') pairs.each { |pairString| key, val = pairString.split('=') props[key] = val ? URI.decode_www_form_component(val) : nil # this is caused by ¶mA¶mB=b, in which case paramA will be nil } end Uri.new(proto, user, pwd, host, port, path, props) end end end |
#port ⇒ Fixnum (readonly)
Returns the port number specified in the URI, can be nil
.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 40 class Uri attr_reader :proto, :user, :pwd, :host, :port, :path, :props =begin rdoc Creates an instance of the object. @param [String] proto see the property {#proto} @param [String] user see the property {#user} @param [String] pwd see the property {#pwd} @param [String] host see the property {#host} @param [String] port see the property {#port} @param [String] path see the property {#path} @param [String] props see the property {#props} =end def initialize(proto, user, pwd, host, port, path, props) raise ArgumentError, 'Password specified but user not' if !user && pwd raise ArgumentError, 'For file protocol, only path can be specified' if proto == 'file' && ( user || pwd || host || port || !props.empty?) @proto, @user, @pwd, @host, @port, @path, @props = proto, user, pwd, host, port, path, props end =begin rdoc Equality to the other =end def ==(other) @proto == other.proto && @user == other.user && @pwd == other.pwd && @host == other.host && @port == other.port && @path == other.path && @props.eql?(other.props) end =begin rdoc Same as the {#==} =end def eql?(other); self == other end =begin rdoc Loads the grammar - has to be done only once per RVM start. Relies on loading the basics. =end def self.loadRulz Treetop.load(File.join(File.dirname(__FILE__), 'urlDataMeta')) end =begin rdoc Instance to textual. =end def to_s if @proto == 'file' "file://#{@path}" else result = '' result << @proto << '://' result << URI.encode_www_form_component(@user) if @user result << ':' << URI.encode_www_form_component(@pwd) if @user && @pwd result << '@' if @user result << @host result << ':' << @port.to_s if @port result << '/' if @path || !@props.empty? result << @path if @path result << '?' << @props.keys.map { |k| v=@props[k]; v ? "#{k}=#{URI.encode_www_form_component(v)}" : "#{k}" }.join('&') unless @props.empty? result end end =begin rdoc Parses the source into the instance of the object. @param [String] source the source, the URI specification to parse into the instance of this class =end def self.parse(source) fileSignature = 'file://' if source.start_with?(fileSignature) Uri.new('file', nil, nil, nil, nil, source[fileSignature.length..-1], {}) else parser = DataMetaUrlParser.new ast = parser.parse(source) return nil unless ast proto = ast.proto.text_value user = ast.user? ? ast.userPwd.user.text_value : nil pwd = ast.pwd? ? URI.decode_www_form_component(ast.userPwd.password) : nil host = ast.host.text_value port = ast.port? ? ast.port.number : nil path = ast.path? ? ast.uTail.path : nil query = ast.query? ? ast.uTail.query : nil props = {} if query pairs = query.split('&') pairs.each { |pairString| key, val = pairString.split('=') props[key] = val ? URI.decode_www_form_component(val) : nil # this is caused by ¶mA¶mB=b, in which case paramA will be nil } end Uri.new(proto, user, pwd, host, port, path, props) end end end |
#props ⇒ Hash (readonly)
Returns hash of properties keyed by the property name and pointing to a value if any.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 40 class Uri attr_reader :proto, :user, :pwd, :host, :port, :path, :props =begin rdoc Creates an instance of the object. @param [String] proto see the property {#proto} @param [String] user see the property {#user} @param [String] pwd see the property {#pwd} @param [String] host see the property {#host} @param [String] port see the property {#port} @param [String] path see the property {#path} @param [String] props see the property {#props} =end def initialize(proto, user, pwd, host, port, path, props) raise ArgumentError, 'Password specified but user not' if !user && pwd raise ArgumentError, 'For file protocol, only path can be specified' if proto == 'file' && ( user || pwd || host || port || !props.empty?) @proto, @user, @pwd, @host, @port, @path, @props = proto, user, pwd, host, port, path, props end =begin rdoc Equality to the other =end def ==(other) @proto == other.proto && @user == other.user && @pwd == other.pwd && @host == other.host && @port == other.port && @path == other.path && @props.eql?(other.props) end =begin rdoc Same as the {#==} =end def eql?(other); self == other end =begin rdoc Loads the grammar - has to be done only once per RVM start. Relies on loading the basics. =end def self.loadRulz Treetop.load(File.join(File.dirname(__FILE__), 'urlDataMeta')) end =begin rdoc Instance to textual. =end def to_s if @proto == 'file' "file://#{@path}" else result = '' result << @proto << '://' result << URI.encode_www_form_component(@user) if @user result << ':' << URI.encode_www_form_component(@pwd) if @user && @pwd result << '@' if @user result << @host result << ':' << @port.to_s if @port result << '/' if @path || !@props.empty? result << @path if @path result << '?' << @props.keys.map { |k| v=@props[k]; v ? "#{k}=#{URI.encode_www_form_component(v)}" : "#{k}" }.join('&') unless @props.empty? result end end =begin rdoc Parses the source into the instance of the object. @param [String] source the source, the URI specification to parse into the instance of this class =end def self.parse(source) fileSignature = 'file://' if source.start_with?(fileSignature) Uri.new('file', nil, nil, nil, nil, source[fileSignature.length..-1], {}) else parser = DataMetaUrlParser.new ast = parser.parse(source) return nil unless ast proto = ast.proto.text_value user = ast.user? ? ast.userPwd.user.text_value : nil pwd = ast.pwd? ? URI.decode_www_form_component(ast.userPwd.password) : nil host = ast.host.text_value port = ast.port? ? ast.port.number : nil path = ast.path? ? ast.uTail.path : nil query = ast.query? ? ast.uTail.query : nil props = {} if query pairs = query.split('&') pairs.each { |pairString| key, val = pairString.split('=') props[key] = val ? URI.decode_www_form_component(val) : nil # this is caused by ¶mA¶mB=b, in which case paramA will be nil } end Uri.new(proto, user, pwd, host, port, path, props) end end end |
#proto ⇒ String (readonly)
Returns the protocol part, such as http
, ftp
, socparc
etc.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 40 class Uri attr_reader :proto, :user, :pwd, :host, :port, :path, :props =begin rdoc Creates an instance of the object. @param [String] proto see the property {#proto} @param [String] user see the property {#user} @param [String] pwd see the property {#pwd} @param [String] host see the property {#host} @param [String] port see the property {#port} @param [String] path see the property {#path} @param [String] props see the property {#props} =end def initialize(proto, user, pwd, host, port, path, props) raise ArgumentError, 'Password specified but user not' if !user && pwd raise ArgumentError, 'For file protocol, only path can be specified' if proto == 'file' && ( user || pwd || host || port || !props.empty?) @proto, @user, @pwd, @host, @port, @path, @props = proto, user, pwd, host, port, path, props end =begin rdoc Equality to the other =end def ==(other) @proto == other.proto && @user == other.user && @pwd == other.pwd && @host == other.host && @port == other.port && @path == other.path && @props.eql?(other.props) end =begin rdoc Same as the {#==} =end def eql?(other); self == other end =begin rdoc Loads the grammar - has to be done only once per RVM start. Relies on loading the basics. =end def self.loadRulz Treetop.load(File.join(File.dirname(__FILE__), 'urlDataMeta')) end =begin rdoc Instance to textual. =end def to_s if @proto == 'file' "file://#{@path}" else result = '' result << @proto << '://' result << URI.encode_www_form_component(@user) if @user result << ':' << URI.encode_www_form_component(@pwd) if @user && @pwd result << '@' if @user result << @host result << ':' << @port.to_s if @port result << '/' if @path || !@props.empty? result << @path if @path result << '?' << @props.keys.map { |k| v=@props[k]; v ? "#{k}=#{URI.encode_www_form_component(v)}" : "#{k}" }.join('&') unless @props.empty? result end end =begin rdoc Parses the source into the instance of the object. @param [String] source the source, the URI specification to parse into the instance of this class =end def self.parse(source) fileSignature = 'file://' if source.start_with?(fileSignature) Uri.new('file', nil, nil, nil, nil, source[fileSignature.length..-1], {}) else parser = DataMetaUrlParser.new ast = parser.parse(source) return nil unless ast proto = ast.proto.text_value user = ast.user? ? ast.userPwd.user.text_value : nil pwd = ast.pwd? ? URI.decode_www_form_component(ast.userPwd.password) : nil host = ast.host.text_value port = ast.port? ? ast.port.number : nil path = ast.path? ? ast.uTail.path : nil query = ast.query? ? ast.uTail.query : nil props = {} if query pairs = query.split('&') pairs.each { |pairString| key, val = pairString.split('=') props[key] = val ? URI.decode_www_form_component(val) : nil # this is caused by ¶mA¶mB=b, in which case paramA will be nil } end Uri.new(proto, user, pwd, host, port, path, props) end end end |
#pwd ⇒ String (readonly)
Returns the password part of the URI, can be nil
and for some URIs may be in properties.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 40 class Uri attr_reader :proto, :user, :pwd, :host, :port, :path, :props =begin rdoc Creates an instance of the object. @param [String] proto see the property {#proto} @param [String] user see the property {#user} @param [String] pwd see the property {#pwd} @param [String] host see the property {#host} @param [String] port see the property {#port} @param [String] path see the property {#path} @param [String] props see the property {#props} =end def initialize(proto, user, pwd, host, port, path, props) raise ArgumentError, 'Password specified but user not' if !user && pwd raise ArgumentError, 'For file protocol, only path can be specified' if proto == 'file' && ( user || pwd || host || port || !props.empty?) @proto, @user, @pwd, @host, @port, @path, @props = proto, user, pwd, host, port, path, props end =begin rdoc Equality to the other =end def ==(other) @proto == other.proto && @user == other.user && @pwd == other.pwd && @host == other.host && @port == other.port && @path == other.path && @props.eql?(other.props) end =begin rdoc Same as the {#==} =end def eql?(other); self == other end =begin rdoc Loads the grammar - has to be done only once per RVM start. Relies on loading the basics. =end def self.loadRulz Treetop.load(File.join(File.dirname(__FILE__), 'urlDataMeta')) end =begin rdoc Instance to textual. =end def to_s if @proto == 'file' "file://#{@path}" else result = '' result << @proto << '://' result << URI.encode_www_form_component(@user) if @user result << ':' << URI.encode_www_form_component(@pwd) if @user && @pwd result << '@' if @user result << @host result << ':' << @port.to_s if @port result << '/' if @path || !@props.empty? result << @path if @path result << '?' << @props.keys.map { |k| v=@props[k]; v ? "#{k}=#{URI.encode_www_form_component(v)}" : "#{k}" }.join('&') unless @props.empty? result end end =begin rdoc Parses the source into the instance of the object. @param [String] source the source, the URI specification to parse into the instance of this class =end def self.parse(source) fileSignature = 'file://' if source.start_with?(fileSignature) Uri.new('file', nil, nil, nil, nil, source[fileSignature.length..-1], {}) else parser = DataMetaUrlParser.new ast = parser.parse(source) return nil unless ast proto = ast.proto.text_value user = ast.user? ? ast.userPwd.user.text_value : nil pwd = ast.pwd? ? URI.decode_www_form_component(ast.userPwd.password) : nil host = ast.host.text_value port = ast.port? ? ast.port.number : nil path = ast.path? ? ast.uTail.path : nil query = ast.query? ? ast.uTail.query : nil props = {} if query pairs = query.split('&') pairs.each { |pairString| key, val = pairString.split('=') props[key] = val ? URI.decode_www_form_component(val) : nil # this is caused by ¶mA¶mB=b, in which case paramA will be nil } end Uri.new(proto, user, pwd, host, port, path, props) end end end |
#user ⇒ String (readonly)
Returns the user id part of the URI, can be nil
and for some URIs may be in properties.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 40 class Uri attr_reader :proto, :user, :pwd, :host, :port, :path, :props =begin rdoc Creates an instance of the object. @param [String] proto see the property {#proto} @param [String] user see the property {#user} @param [String] pwd see the property {#pwd} @param [String] host see the property {#host} @param [String] port see the property {#port} @param [String] path see the property {#path} @param [String] props see the property {#props} =end def initialize(proto, user, pwd, host, port, path, props) raise ArgumentError, 'Password specified but user not' if !user && pwd raise ArgumentError, 'For file protocol, only path can be specified' if proto == 'file' && ( user || pwd || host || port || !props.empty?) @proto, @user, @pwd, @host, @port, @path, @props = proto, user, pwd, host, port, path, props end =begin rdoc Equality to the other =end def ==(other) @proto == other.proto && @user == other.user && @pwd == other.pwd && @host == other.host && @port == other.port && @path == other.path && @props.eql?(other.props) end =begin rdoc Same as the {#==} =end def eql?(other); self == other end =begin rdoc Loads the grammar - has to be done only once per RVM start. Relies on loading the basics. =end def self.loadRulz Treetop.load(File.join(File.dirname(__FILE__), 'urlDataMeta')) end =begin rdoc Instance to textual. =end def to_s if @proto == 'file' "file://#{@path}" else result = '' result << @proto << '://' result << URI.encode_www_form_component(@user) if @user result << ':' << URI.encode_www_form_component(@pwd) if @user && @pwd result << '@' if @user result << @host result << ':' << @port.to_s if @port result << '/' if @path || !@props.empty? result << @path if @path result << '?' << @props.keys.map { |k| v=@props[k]; v ? "#{k}=#{URI.encode_www_form_component(v)}" : "#{k}" }.join('&') unless @props.empty? result end end =begin rdoc Parses the source into the instance of the object. @param [String] source the source, the URI specification to parse into the instance of this class =end def self.parse(source) fileSignature = 'file://' if source.start_with?(fileSignature) Uri.new('file', nil, nil, nil, nil, source[fileSignature.length..-1], {}) else parser = DataMetaUrlParser.new ast = parser.parse(source) return nil unless ast proto = ast.proto.text_value user = ast.user? ? ast.userPwd.user.text_value : nil pwd = ast.pwd? ? URI.decode_www_form_component(ast.userPwd.password) : nil host = ast.host.text_value port = ast.port? ? ast.port.number : nil path = ast.path? ? ast.uTail.path : nil query = ast.query? ? ast.uTail.query : nil props = {} if query pairs = query.split('&') pairs.each { |pairString| key, val = pairString.split('=') props[key] = val ? URI.decode_www_form_component(val) : nil # this is caused by ¶mA¶mB=b, in which case paramA will be nil } end Uri.new(proto, user, pwd, host, port, path, props) end end end |
Class Method Details
.loadRulz ⇒ Object
Loads the grammar - has to be done only once per RVM start. Relies on loading the basics.
78 79 80 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 78 def self.loadRulz Treetop.load(File.join(File.dirname(__FILE__), 'urlDataMeta')) end |
.parse(source) ⇒ Object
Parses the source into the instance of the object.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 111 def self.parse(source) fileSignature = 'file://' if source.start_with?(fileSignature) Uri.new('file', nil, nil, nil, nil, source[fileSignature.length..-1], {}) else parser = DataMetaUrlParser.new ast = parser.parse(source) return nil unless ast proto = ast.proto.text_value user = ast.user? ? ast.userPwd.user.text_value : nil pwd = ast.pwd? ? URI.decode_www_form_component(ast.userPwd.password) : nil host = ast.host.text_value port = ast.port? ? ast.port.number : nil path = ast.path? ? ast.uTail.path : nil query = ast.query? ? ast.uTail.query : nil props = {} if query pairs = query.split('&') pairs.each { |pairString| key, val = pairString.split('=') props[key] = val ? URI.decode_www_form_component(val) : nil # this is caused by ¶mA¶mB=b, in which case paramA will be nil } end Uri.new(proto, user, pwd, host, port, path, props) end end |
Instance Method Details
#==(other) ⇒ Object
Equality to the other
65 66 67 68 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 65 def ==(other) @proto == other.proto && @user == other.user && @pwd == other.pwd && @host == other.host && @port == other.port && @path == other.path && @props.eql?(other.props) end |
#eql?(other) ⇒ Boolean
Same as the #==
73 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 73 def eql?(other); self == other end |
#to_s ⇒ Object
Instance to textual.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/dataMetaParse/uriDataMeta.rb', line 85 def to_s if @proto == 'file' "file://#{@path}" else result = '' result << @proto << '://' result << URI.encode_www_form_component(@user) if @user result << ':' << URI.encode_www_form_component(@pwd) if @user && @pwd result << '@' if @user result << @host result << ':' << @port.to_s if @port result << '/' if @path || !@props.empty? result << @path if @path result << '?' << @props.keys.map { |k| v=@props[k]; v ? "#{k}=#{URI.encode_www_form_component(v)}" : "#{k}" }.join('&') unless @props.empty? result end end |