Skip to content

Instantly share code, notes, and snippets.

@atomgiant
Created May 7, 2020 17:50
Show Gist options
  • Save atomgiant/2c160d6dcd913964027116f126ed5cea to your computer and use it in GitHub Desktop.
Save atomgiant/2c160d6dcd913964027116f126ed5cea to your computer and use it in GitHub Desktop.
module Liquid
class ProductMock
attr_accessor :id, :collections, :variants, :created_at, :tags
def initialize(id: 123, collections: [], variants:[], created_at: Date.yesterday, tags:[])
@collections = []
@variants = variants
@created_at = created_at
@tags = tags
end
def price_min
@variants.map { |e| e.price }.min
end
def price_max
@variants.map { |e| e.price }.max
end
def to_liquid
{
'id' => @id,
'collections' => @collections,
'variants' => @variants,
'created_at' => @created_at,
'tags' => @tags,
'price_min' => price_min,
'price_max' => price_max,
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment