Class: Useless::Doc::Router::Default
- Inherits:
-
Object
- Object
- Useless::Doc::Router::Default
- Includes:
- Useless::Doc::Router
- Defined in:
- lib/useless/doc/router.rb
Instance Method Summary collapse
- #api_for_doc(url) ⇒ Object
- #doc_for_api(url) ⇒ Object
-
#initialize(*supported_urls) ⇒ Default
constructor
A new instance of Default.
Methods included from Useless::Doc::Router
Constructor Details
#initialize(*supported_urls) ⇒ Default
Returns a new instance of Default.
23 24 25 |
# File 'lib/useless/doc/router.rb', line 23 def initialize(*supported_urls) @supported_urls = supported_urls end |
Instance Method Details
#api_for_doc(url) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/useless/doc/router.rb', line 38 def api_for_doc(url) uri = URI(url) host = uri.host parts = host.split('.') parts.slice!(-3) if parts[-3] == 'doc' new_host = parts.join('.') new_url = "#{uri.scheme}://#{new_host}#{uri.path}" new_url if supported_url?(new_url) end |
#doc_for_api(url) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/useless/doc/router.rb', line 27 def doc_for_api(url) return nil unless supported_url?(url) uri = URI(url) host = uri.host new_host = host. split('.'). insert(-3, 'doc'). join('.') "#{uri.scheme}://#{new_host}#{uri.path}" end |