Class: CardmarketCLI::Entities::WantslistItem
- Inherits:
-
Changeable
- Object
- Entity
- Changeable
- CardmarketCLI::Entities::WantslistItem
- Defined in:
- lib/cardmarket_cli/entities/wantslist_item.rb
Overview
Constant Summary collapse
- PARAMS =
%i[count from_price min_condition wish_price mail_alert languages is_foil is_altered is_playset is_signed is_first_ed].freeze
Instance Attribute Summary collapse
-
#product ⇒ Object
readonly
Returns the value of attribute product.
Attributes inherited from Entity
Class Method Summary collapse
Instance Method Summary collapse
- #add_product_id(hash) ⇒ Object
-
#initialize(id, product, account, params = {}) ⇒ WantslistItem
constructor
A new instance of WantslistItem.
- #languages ⇒ Object
- #languages=(value) ⇒ Object
- #meta? ⇒ Boolean
- #to_xml_hash ⇒ Object
Methods inherited from Changeable
Constructor Details
#initialize(id, product, account, params = {}) ⇒ WantslistItem
Returns a new instance of WantslistItem.
18 19 20 21 22 23 |
# File 'lib/cardmarket_cli/entities/wantslist_item.rb', line 18 def initialize(id, product, account, params = {}) params = { count: 1, min_condition: :PO, wish_price: 0.0, mail_alert: false, languages: [1], is_foil: nil, is_altered: nil, is_playset: nil, is_signed: nil, is_first_ed: nil, from_price: nil }.merge!(params) super(id, account, params.slice(*PARAMS)) @product = product end |
Instance Attribute Details
#product ⇒ Object (readonly)
Returns the value of attribute product.
16 17 18 |
# File 'lib/cardmarket_cli/entities/wantslist_item.rb', line 16 def product @product end |
Class Method Details
.from_hash(account, hash) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/cardmarket_cli/entities/wantslist_item.rb', line 58 def from_hash(account, hash) product = create_product(account, hash) hash.transform_keys! { |key| key.underscore.to_sym } hash[:min_condition] &&= hash[:min_condition].to_sym hash[:languages] = hash[:id_language] WantslistItem.new(hash[:id_want], product, account, hash) end |
Instance Method Details
#add_product_id(hash) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/cardmarket_cli/entities/wantslist_item.rb', line 35 def add_product_id(hash) return if hash['idWant'] if @product. hash[:idMetaproduct] = @product.id else hash[:idProduct] = @product.id end end |
#languages ⇒ Object
49 50 51 |
# File 'lib/cardmarket_cli/entities/wantslist_item.rb', line 49 def languages params[:languages]&.uniq! end |
#languages=(value) ⇒ Object
53 54 55 |
# File 'lib/cardmarket_cli/entities/wantslist_item.rb', line 53 def languages=(value) params[:languages] = value.uniq end |
#meta? ⇒ Boolean
45 46 47 |
# File 'lib/cardmarket_cli/entities/wantslist_item.rb', line 45 def product. end |
#to_xml_hash ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/cardmarket_cli/entities/wantslist_item.rb', line 25 def to_xml_hash hash = params.compact.transform_keys! { |key| key.to_s.camelize } hash['idLanguage'] = hash.delete('languages')&.uniq! hash['idWant'] = id hash.delete_if { |_, value| value.nil? || (value.respond_to?(:empty?) && value.empty?) } add_product_id(hash) hash end |