Class: Prestashop::Mapper::Supplier

Inherits:
Model
  • Object
show all
Defined in:
lib/prestashop/mapper/models/supplier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#hash_lang, model, resource

Methods included from Extension

included

Constructor Details

#initialize(args = {}) ⇒ Supplier

Returns a new instance of Supplier.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/prestashop/mapper/models/supplier.rb', line 11

def initialize args = {}
  @id               = args[:id]
  @link_rewrite     = args[:link_rewrite]
  @name             = args.fetch(:name)
  @active           = args.fetch(:active, 1)
  # date_add
  # date_upd
  @description      = args[:description]
  @meta_title       = args[:meta_title]
  @meta_description = args[:meta_description]
  @meta_keywords    = args[:meta_keywords]

  @id_lang          = args[:id_lang]
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



8
9
10
# File 'lib/prestashop/mapper/models/supplier.rb', line 8

def active
  @active
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/prestashop/mapper/models/supplier.rb', line 8

def description
  @description
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/prestashop/mapper/models/supplier.rb', line 8

def id
  @id
end

#id_langObject

Returns the value of attribute id_lang.



9
10
11
# File 'lib/prestashop/mapper/models/supplier.rb', line 9

def id_lang
  @id_lang
end

Returns the value of attribute link_rewrite.



8
9
10
# File 'lib/prestashop/mapper/models/supplier.rb', line 8

def link_rewrite
  @link_rewrite
end

#meta_descriptionObject

Returns the value of attribute meta_description.



8
9
10
# File 'lib/prestashop/mapper/models/supplier.rb', line 8

def meta_description
  @meta_description
end

#meta_keywordsObject

Returns the value of attribute meta_keywords.



8
9
10
# File 'lib/prestashop/mapper/models/supplier.rb', line 8

def meta_keywords
  @meta_keywords
end

#meta_titleObject

Returns the value of attribute meta_title.



8
9
10
# File 'lib/prestashop/mapper/models/supplier.rb', line 8

def meta_title
  @meta_title
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/prestashop/mapper/models/supplier.rb', line 8

def name
  @name
end

Instance Method Details

#find_or_createObject

Find or create supplier from hash



33
34
35
36
# File 'lib/prestashop/mapper/models/supplier.rb', line 33

def find_or_create
  supplier = self.class.find_by 'filter[name]' => name
  supplier ? supplier : create[:id]
end

#hashObject

Hash is used as default source for #create



27
28
29
30
# File 'lib/prestashop/mapper/models/supplier.rb', line 27

def hash
  validate!
  { active: active, name: name }
end

#validate!Object

Supplier must have 1/0 as active and name must be string

Raises:

  • (ArgumentError)


39
40
41
42
# File 'lib/prestashop/mapper/models/supplier.rb', line 39

def validate!
  raise ArgumentError, 'active must be 0 or 1' unless active == 0 or active == 1
  raise ArgumentError, 'name must string' unless name.kind_of?(String)
end