Class: Prestashop::Mapper::Manufacturer
- Defined in:
- lib/prestashop/mapper/models/manufacturer.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
- #description ⇒ Object
-
#id ⇒ Object
Returns the value of attribute id.
-
#id_lang ⇒ Object
Returns the value of attribute id_lang.
-
#link_rewrite ⇒ Object
writeonly
Sets the attribute link_rewrite.
-
#meta_description ⇒ Object
writeonly
Sets the attribute meta_description.
-
#meta_keywords ⇒ Object
writeonly
Sets the attribute meta_keywords.
-
#meta_title ⇒ Object
writeonly
Sets the attribute meta_title.
- #name ⇒ Object
- #short_description ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #find_or_create ⇒ Object
- #hash ⇒ Object
-
#initialize(args = {}) ⇒ Manufacturer
constructor
A new instance of Manufacturer.
- #validate! ⇒ Object
Methods inherited from Model
#hash_lang, #meta_description, #meta_keywords, #meta_title, model, resource
Methods included from Extension
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
#active ⇒ Object
Returns the value of attribute active.
8 9 10 |
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 8 def active @active end |
#description ⇒ Object
32 33 34 |
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 32 def description @description.plain.truncate(252) if @description end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 8 def id @id end |
#id_lang ⇒ Object
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 |
#link_rewrite=(value) ⇒ Object (writeonly)
Sets the attribute link_rewrite
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
10 11 12 |
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 10 def (value) @meta_description = value end |
#meta_keywords=(value) ⇒ Object (writeonly)
Sets the attribute meta_keywords
10 11 12 |
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 10 def (value) @meta_keywords = value end |
#meta_title=(value) ⇒ Object (writeonly)
Sets the attribute meta_title
10 11 12 |
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 10 def (value) @meta_title = value end |
#name ⇒ Object
28 29 30 |
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 28 def name @name.plain.truncate(125) end |
#short_description ⇒ Object
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
.cache ⇒ Object
73 74 75 |
# File 'lib/prestashop/mapper/models/manufacturer.rb', line 73 def cache all display: '[id,name]' end |
Instance Method Details
#find_or_create ⇒ Object
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 |
#hash ⇒ Object
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(, id_lang) } end |
#validate! ⇒ Object
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 |