Class: Envconfig::UrlParser
- Inherits:
-
Object
- Object
- Envconfig::UrlParser
- Defined in:
- lib/envconfig/url_parser.rb
Instance Method Summary collapse
-
#extract(*keys) ⇒ Object
Extract the given keys verbatim from the URL.
-
#extract_as(mapping) ⇒ Object
Extract and rename the given keys.
-
#initialize(url) ⇒ UrlParser
constructor
A new instance of UrlParser.
-
#query_values ⇒ Object
Query string as hash with symbol keys.
Constructor Details
#initialize(url) ⇒ UrlParser
Returns a new instance of UrlParser.
7 8 9 |
# File 'lib/envconfig/url_parser.rb', line 7 def initialize(url) @url = url end |
Instance Method Details
#extract(*keys) ⇒ Object
Extract the given keys verbatim from the URL. These map to public instance methods on URI.
13 14 15 16 17 |
# File 'lib/envconfig/url_parser.rb', line 13 def extract(*keys) keys.inject({}) do |hash, key| hash.merge!(key => parsed_url.public_send(key)) end end |
#extract_as(mapping) ⇒ Object
Extract and rename the given keys. The mapping keys are the wanted keys, the mapping values are public instance methods on URI.
22 23 24 25 26 |
# File 'lib/envconfig/url_parser.rb', line 22 def extract_as(mapping) mapping.inject({}) do |hash, (key, method)| hash.merge!(key => extract_value(method)) end end |
#query_values ⇒ Object
Query string as hash with symbol keys.
29 30 31 32 33 |
# File 'lib/envconfig/url_parser.rb', line 29 def query_values CGI.parse(parsed_url.query || "").inject({}) do |hash, (key, values)| hash.merge!(key.to_sym => values.first) end end |