Files

HTTPClient::Util

A module for common function.

Public Class Methods

hash_find_value(hash, &block) click to toggle source

Finds a value of a Hash.

    # File lib/httpclient/util.rb, line 78
78:     def hash_find_value(hash, &block)
79:       v = hash.find(&block)
80:       v ? v[1] : nil
81:     end
uri_dirname(uri) click to toggle source

Returns parent directory URI of the given URI.

    # File lib/httpclient/util.rb, line 70
70:     def uri_dirname(uri)
71:       uri = uri.clone
72:       uri.path = uri.path.sub(/\/[^\/]*\z/, '/')
73:       uri
74:     end
uri_part_of(uri, part) click to toggle source

Returns true if the given 2 URIs have a part_of relationship.

  • the same scheme

  • the same host String (no host resolution or IP-addr conversion)

  • the same port number

  • target URI’s path starts with base URI’s path.

    # File lib/httpclient/util.rb, line 61
61:     def uri_part_of(uri, part)
62:       ((uri.scheme == part.scheme) and
63:        (uri.host == part.host) and
64:        (uri.port == part.port) and
65:        uri.path.upcase.index(part.path.upcase) == 0)
66:     end

Public Instance Methods

keyword_argument(args, *field) click to toggle source

Keyword argument helper.

args

given arguments.

*field

a list of arguments to be extracted.

You can extract 3 arguments (a, b, c) with:

  include Util
  def my_method(*args)
    a, b, c = keyword_argument(args, :a, :b, :c)
    ...
  end
  my_method(1, 2, 3)
  my_method(:b => 2, :a = 1)

instead of;

  def my_method(a, b, c)
    ...
  end
    # File lib/httpclient/util.rb, line 37
37:     def keyword_argument(args, *field)
38:       if args.size == 1 and args[0].is_a?(Hash)
39:         args[0].values_at(*field)
40:       else
41:         args
42:       end
43:     end
urify(uri) click to toggle source

Gets an URI instance.

    # File lib/httpclient/util.rb, line 46
46:     def urify(uri)
47:       if uri.nil?
48:         nil
49:       elsif uri.is_a?(URI)
50:         uri
51:       else
52:         URI.parse(uri.to_s)
53:       end
54:     end

Private Instance Methods

hash_find_value(hash, &block) click to toggle source

Finds a value of a Hash.

    # File lib/httpclient/util.rb, line 78
78:     def hash_find_value(hash, &block)
79:       v = hash.find(&block)
80:       v ? v[1] : nil
81:     end
uri_dirname(uri) click to toggle source

Returns parent directory URI of the given URI.

    # File lib/httpclient/util.rb, line 70
70:     def uri_dirname(uri)
71:       uri = uri.clone
72:       uri.path = uri.path.sub(/\/[^\/]*\z/, '/')
73:       uri
74:     end
uri_part_of(uri, part) click to toggle source

Returns true if the given 2 URIs have a part_of relationship.

  • the same scheme

  • the same host String (no host resolution or IP-addr conversion)

  • the same port number

  • target URI’s path starts with base URI’s path.

    # File lib/httpclient/util.rb, line 61
61:     def uri_part_of(uri, part)
62:       ((uri.scheme == part.scheme) and
63:        (uri.host == part.host) and
64:        (uri.port == part.port) and
65:        uri.path.upcase.index(part.path.upcase) == 0)
66:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.