Class: Prestashop::Mapper::Manufacturer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#hash_lang, #meta_description, #meta_keywords, #meta_title, model, resource

Methods included from Extension

included

Constructor Details

#initialize(args = {}) ⇒ Manufacturer

Returns a new instance of Manufacturer.


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

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

  @id_lang            = args.fetch(:id_lang)
end

Instance Attribute Details

#activeObject

Returns the value of attribute active


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

def active
  @active
end

#descriptionObject


32
33
34
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 32

def description
  @description.plain.truncate(252) if @description
end

#idObject

Returns the value of attribute id


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

def id
  @id
end

#id_langObject

Returns the value of attribute id_lang


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

def id_lang
  @id_lang
end

Sets the attribute link_rewrite

Parameters:

  • value

    the value to set the attribute link_rewrite to.


10
11
12
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 10

def link_rewrite=(value)
  @link_rewrite = value
end

#meta_description=(value) ⇒ Object (writeonly)

Sets the attribute meta_description

Parameters:

  • value

    the value to set the attribute meta_description to.


10
11
12
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 10

def meta_description=(value)
  @meta_description = value
end

#meta_keywords=(value) ⇒ Object (writeonly)

Sets the attribute meta_keywords

Parameters:

  • value

    the value to set the attribute meta_keywords to.


10
11
12
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 10

def meta_keywords=(value)
  @meta_keywords = value
end

#meta_title=(value) ⇒ Object (writeonly)

Sets the attribute meta_title

Parameters:

  • value

    the value to set the attribute meta_title to.


10
11
12
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 10

def meta_title=(value)
  @meta_title = value
end

#nameObject


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

def name
  @name.plain.truncate(125)
end

#short_descriptionObject


36
37
38
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 36

def short_description
  @short_description ? @short_description.plain.truncate(252) : ( description.plain.truncate(252) if description )
end

Class Method Details

.cacheObject


73
74
75
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 73

def cache
  all display: '[id,name]'
end

.find_in_cache(name) ⇒ Object


69
70
71
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 69

def find_in_cache name
  Client.manufacturers_cache.find{|m| m[:name] == name } if Client.manufacturers_cache
end

Instance Method Details

#find_or_createObject


51
52
53
54
55
56
57
58
59
60
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 51

def find_or_create
  if name and !name.empty?
    manufacturer = self.class.find_in_cache name
    unless manufacturer
      manufacturer = create
      Client.clear_manufacturers_cache
    end
    manufacturer[:id]
  end
end

#hashObject


40
41
42
43
44
45
46
47
48
49
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 40

def hash
  validate!
  { active:             active,
    name:               name,
    description:        hash_lang(description, id_lang),
    short_description:  hash_lang(short_description, id_lang),
    meta_title:         hash_lang(name, id_lang),
    meta_description:   hash_lang(short_description, id_lang),
    meta_keywords:      hash_lang(meta_keywords, id_lang) }      
end

#validate!Object

Raises:

  • (ArgumentError)

62
63
64
65
66
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 62

def validate!
  raise ArgumentError, 'id lang must be number' unless id_lang.kind_of?(Integer)
  raise ArgumentError, 'active must be number' unless active.kind_of?(Integer)
  raise ArgumentError, 'name must string' unless name.kind_of?(String)
end