Class: FoxycartHelpers::Link
- Inherits:
-
Object
- Object
- FoxycartHelpers::Link
- Defined in:
- lib/foxycart_helpers/link.rb
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
- #encoded_query_hash ⇒ Object
- #href ⇒ Object
-
#initialize(name, price, code = nil, opts = {}) ⇒ Link
constructor
A new instance of Link.
- #query_hash ⇒ Object
- #query_string ⇒ Object
Constructor Details
#initialize(name, price, code = nil, opts = {}) ⇒ Link
Returns a new instance of Link.
40 41 42 43 44 45 |
# File 'lib/foxycart_helpers/link.rb', line 40 def initialize(name, price, code=nil, opts={}) @name = name @price = price @code = code @opts = opts end |
Class Method Details
.href(*args) ⇒ Object
8 9 10 |
# File 'lib/foxycart_helpers/link.rb', line 8 def self.href(*args) new(*args).href end |
Instance Method Details
#config ⇒ Object
47 48 49 |
# File 'lib/foxycart_helpers/link.rb', line 47 def config FoxycartHelpers.configuration end |
#encoded_query_hash ⇒ Object
36 37 38 |
# 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 ⇒ Object
12 13 14 15 16 17 18 |
# 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 ⇒ Object
28 29 30 31 32 33 34 |
# 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 ⇒ Object
20 21 22 23 24 25 26 |
# 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 |