Class: Ingenico::Direct::SDK::Domain::ShoppingCartExtension

Inherits:
Ingenico::Direct::SDK::DataObject show all
Defined in:
lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb

Overview

Represents metadata part of shopping carts.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(creator, name, version, extension_id = nil) ⇒ ShoppingCartExtension

Returns a new instance of ShoppingCartExtension.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
# File 'lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb', line 7

def initialize(creator, name, version, extension_id = nil)
  raise ArgumentError if creator.nil? || creator.strip.empty?
  raise ArgumentError if name.nil? || name.strip.empty?
  raise ArgumentError if version.nil? || version.to_s.strip.empty?

  @creator = creator
  @name = name
  @version = version.to_s
  @extension_id = extension_id
end

Instance Attribute Details

#creatorObject (readonly)

Returns the value of attribute creator.



50
51
52
# File 'lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb', line 50

def creator
  @creator
end

#extension_idObject (readonly)

Returns the value of attribute extension_id.



50
51
52
# File 'lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb', line 50

def extension_id
  @extension_id
end

#nameObject (readonly)

Returns the value of attribute name.



50
51
52
# File 'lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb', line 50

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



50
51
52
# File 'lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb', line 50

def version
  @version
end

Class Method Details

.new_from_hash(hash) ⇒ Object

Constructs a new ShoppingCartExtension from parameter hash the hash should contain a creator, name, version and extensionId – Overridden so ShoppingCartExtension can retain mandatory default arguments ++



23
24
25
26
27
28
29
# File 'lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb', line 23

def self.new_from_hash(hash)
  creator = hash['creator'] if hash.has_key?('creator')
  name = hash['name'] if hash.has_key?('name')
  version = hash['version'] if hash.has_key?('version')
  extension_id = hash['extensionId'] if hash.has_key?('extensionId')
  self.new(creator, name, version, extension_id)
end

Instance Method Details

#from_hash(hash) ⇒ Object

loads shopping cart metadata from a parameter hash



42
43
44
45
46
47
48
# File 'lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb', line 42

def from_hash(hash)
  super
  @creator = hash['creator'] if hash.has_key? 'creator'
  @name = hash['name'] if hash.has_key? 'name'
  @version = hash['version'] if hash.has_key? 'version'
  @extension_id = hash['extensionId'] if hash.has_key? 'extensionId'
end

#to_hObject

Converts the shopping cart metadata to a hash



32
33
34
35
36
37
38
39
# File 'lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb', line 32

def to_h
  hash = super
  hash['creator'] = @creator unless @creator.nil?
  hash['name'] = @name unless @name.nil?
  hash['version'] = @version unless @version.nil?
  hash['extensionId'] = @extension_id unless @extension_id.nil?
  hash
end