class Prestashop::Mapper::Manufacturer

Attributes

active[RW]
description[W]
id[RW]
id_lang[RW]
meta_description[W]
meta_keywords[W]
meta_title[W]
name[W]
short_description[W]

Public Class Methods

cache() click to toggle source
# File lib/prestashop/mapper/models/manufacturer.rb, line 73
def cache
  all display: '[id,name]'
end
find_in_cache(name) click to toggle source
# 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
new(args = {}) click to toggle source
# 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

Public Instance Methods

description() click to toggle source
# File lib/prestashop/mapper/models/manufacturer.rb, line 32
def description
  @description.plain.truncate(252) if @description
end
find_or_create() click to toggle source
# 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
hash() click to toggle source
# 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
name() click to toggle source
# File lib/prestashop/mapper/models/manufacturer.rb, line 28
def name
  @name.plain.truncate(125)
end
short_description() click to toggle source
# 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
validate!() click to toggle source
# 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