Class: PricesUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/model/prices_url.rb

Defined Under Namespace

Classes: InvalidURL

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ PricesUrl

Returns a new instance of PricesUrl.

Raises:



3
4
5
6
# File 'lib/model/prices_url.rb', line 3

def initialize(url)
  raise InvalidURL, "You must give an url, ie http://www.ns.nl/api" unless url
  @url = url
end

Instance Method Details

#url(opts = {date: nil, from: "", to: ""}) ⇒ Object



8
9
10
11
12
# File 'lib/model/prices_url.rb', line 8

def url (opts = {date: nil, from: "", to: ""})
  opts[:date] = opts[:date].strftime("%d%m%Y") if opts[:date]
  uri = URI.escape(opts.collect{|k,v| "#{k}=#{v}"}.join('&'))
  "#{@url}?#{uri}"
end