Module: Imglab

Defined in:
lib/imglab.rb,
lib/imglab/version.rb

Defined Under Namespace

Modules: Color, Position Classes: Signature, Source, Utils

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.url(source_name_or_source, path, params = {}) ⇒ String

Returns a formatted URL ‘string` with the specified arguments.

Examples:

Creating a URL specifying source name as string

Imglab.url("assets", "example.jpeg", width: 500, height: 600) #=> "https://cdn.imglab.io/assets/example.jpeg?width=500&height=600"

Creating a URL specifying a Imglab::Source

Imglab.url(Imglab::Source.new("assets"), "example.jpeg", width: 500, height: 600) #=> "https://cdn.imglab.io/assets/example.jpeg?width=500&height=600"

Parameters:

  • source_name_or_source (String, Imglab::Source)

    the source name or source object

  • path (String)

    the path where the resource is located

  • params (Hash) (defaults to: {})

    the query parameters that we want to use

Returns:

  • (String)

    the formatted URL with the specified arguments

Raises:

  • (ArgumentError)

    when the source name or source parameter has a not expected type.



23
24
25
26
27
28
29
30
31
32
# File 'lib/imglab.rb', line 23

def self.url(source_name_or_source, path, params = {})
  case source_name_or_source
  when String
    url_for_source(Source.new(source_name_or_source), path, params)
  when Source
    url_for_source(source_name_or_source, path, params)
  else
    raise ArgumentError.new("Invalid source name or source. A string or #{Imglab::Source.name} is expected.")
  end
end