class FoxycartHelpers::Link
Public Class Methods
href(*args)
click to toggle source
# File lib/foxycart_helpers/link.rb, line 8 def self.href(*args) new(*args).href end
new(name, price, code=nil, opts={})
click to toggle source
# File lib/foxycart_helpers/link.rb, line 40 def initialize(name, price, code=nil, opts={}) @name = name @price = price @code = code @opts = opts end
Public Instance Methods
config()
click to toggle source
# File lib/foxycart_helpers/link.rb, line 47 def config FoxycartHelpers.configuration end
encoded_query_hash()
click to toggle source
# File lib/foxycart_helpers/link.rb, line 36 def encoded_query_hash query_hash.map {|k,v| [k, FoxycartHelpers::ProductVerification.encoded_name(@code, k.to_s, v)]}.to_h end
href()
click to toggle source
# File lib/foxycart_helpers/link.rb, line 12 def href url = URI::parse config.url url.path = '/cart' url.query = query_string url.to_s end
query_hash()
click to toggle source
# File lib/foxycart_helpers/link.rb, line 28 def query_hash Hash.new.tap do |h| h[:name] = @name h[:price] = @price h[:code] = @code if @code end.merge(@opts) end
query_string()
click to toggle source
# File lib/foxycart_helpers/link.rb, line 20 def query_string params = config.auto_encode_hrefs? ? encoded_query_hash : query_hash string = URI.encode_www_form(params) return string unless config.auto_encode_hrefs? CGI.unescape string end