Class: Prestashop::Mapper::ProductFeatureValue
- Defined in:
- lib/prestashop/mapper/models/product_feature_value.rb
Instance Attribute Summary collapse
-
#custom ⇒ Object
Returns the value of attribute custom.
-
#id ⇒ Object
Returns the value of attribute id.
-
#id_feature ⇒ Object
Returns the value of attribute id_feature.
-
#id_lang ⇒ Object
Returns the value of attribute id_lang.
- #value ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #find_or_create ⇒ Object
- #hash ⇒ Object
-
#initialize(args = {}) ⇒ ProductFeatureValue
constructor
A new instance of ProductFeatureValue.
- #validate! ⇒ Object
Methods inherited from Model
#hash_lang, #meta_description, #meta_keywords, #meta_title, model, resource
Methods included from Extension
Constructor Details
#initialize(args = {}) ⇒ ProductFeatureValue
Returns a new instance of ProductFeatureValue.
12 13 14 15 16 17 18 19 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 12 def initialize args = {} @id = args[:id] @id_feature = args.fetch(:id_feature) @custom = args.fetch(:custom, 0) @value = args.fetch(:value) @id_lang = args.fetch(:id_lang) end |
Instance Attribute Details
#custom ⇒ Object
Returns the value of attribute custom.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 8 def custom @custom end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 8 def id @id end |
#id_feature ⇒ Object
Returns the value of attribute id_feature.
8 9 10 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 8 def id_feature @id_feature end |
#id_lang ⇒ Object
Returns the value of attribute id_lang.
10 11 12 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 10 def id_lang @id_lang end |
#value ⇒ Object
21 22 23 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 21 def value @value.plain end |
Class Method Details
.cache ⇒ Object
54 55 56 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 54 def cache all display: '[id,id_feature,value]' end |
.find_in_cache(id_feature, value, id_lang) ⇒ Object
50 51 52 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 50 def find_in_cache id_feature, value, id_lang Client.feature_values_cache.find{|v| v[:id_feature] == id_feature and v[:value].find_lang(value, id_lang)} if Client.feature_values_cache end |
Instance Method Details
#find_or_create ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 33 def find_or_create result = self.class.find_in_cache id_feature, value, id_lang unless result result = create Client.clear_feature_values_cache end result[:id] end |
#hash ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 25 def hash validate! { id_feature: id_feature, custom: custom, value: hash_lang(value, id_lang) } end |
#validate! ⇒ Object
42 43 44 45 46 47 |
# File 'lib/prestashop/mapper/models/product_feature_value.rb', line 42 def validate! raise ArgumentError, 'id lang must be number' unless id_lang.kind_of?(Integer) raise ArgumentError, 'id feature must string' unless id_feature.kind_of?(Integer) raise ArgumentError, 'custom must be 0 or 1' unless custom == 0 or custom == 1 raise ArgumentError, 'value must string' unless value.kind_of?(String) end |