Class: Worldline::Connect::SDK::Domain::ShoppingCartExtension

Inherits:
DataObject
  • Object
show all
Defined in:
lib/worldline/connect/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)


14
15
16
17
18
19
20
21
22
23
# File 'lib/worldline/connect/sdk/domain/shopping_cart_extension.rb', line 14

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

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

Instance Attribute Details

#creatorString (readonly)

Returns the current value of creator.

Returns:

  • (String)

    the current value of creator



13
14
15
# File 'lib/worldline/connect/sdk/domain/shopping_cart_extension.rb', line 13

def creator
  @creator
end

#extension_idString (readonly)

Returns the current value of extension_id.

Returns:

  • (String)

    the current value of extension_id



13
14
15
# File 'lib/worldline/connect/sdk/domain/shopping_cart_extension.rb', line 13

def extension_id
  @extension_id
end

#nameString (readonly)

Returns the current value of name.

Returns:

  • (String)

    the current value of name



13
14
15
# File 'lib/worldline/connect/sdk/domain/shopping_cart_extension.rb', line 13

def name
  @name
end

#versionString (readonly)

Returns the current value of version.

Returns:

  • (String)

    the current value of version



13
14
15
# File 'lib/worldline/connect/sdk/domain/shopping_cart_extension.rb', line 13

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 ++



30
31
32
33
34
35
36
# File 'lib/worldline/connect/sdk/domain/shopping_cart_extension.rb', line 30

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



49
50
51
52
53
54
55
# File 'lib/worldline/connect/sdk/domain/shopping_cart_extension.rb', line 49

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



39
40
41
42
43
44
45
46
# File 'lib/worldline/connect/sdk/domain/shopping_cart_extension.rb', line 39

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