Project

mercadona

0.0
The project is in a healthy, maintained state
Simple retail shop interface.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 6.4, >= 6.4.4
~> 13.2, >= 13.2.1
~> 3.13
 Project Readme

Simple retail shop interface

Maintainability Test Coverage CircleCI Gem Version Downloads GitHub Contributor Covenant

mercadona - Simple retail shop interface.

Table of Contents

  • Requirements
  • Installation
  • Usage
    • Customization
  • Contributing
  • License
  • Code of Conduct
  • Credits
  • Versioning
  • Changelog

Requirements

Ruby MRI 2.5.0+

Installation

Add this line to your application's Gemfile:

gem 'mercadona'

And then execute:

bundle

Or install it yourself as:

gem install mercadona

Usage

require 'mercadona'

# Define discount rules
bogo_discount = Mercadona::Entity::DiscountRule.new(type: Mercadona::Discount::Bogo, condition: '>=', quantity: 2)
quantity_discount = Mercadona::Entity::DiscountRule.new(type: Mercadona::Discount::Quantity, condition: '>=', quantity: 3, discount: 0.5)
bulk_discount = Mercadona::Entity::DiscountRule.new(type: Mercadona::Discount::Bulk, condition: '>=', quantity: 3, discount: 1/3r)

# Define checkout with discount rules specified through product codes
checkout = Mercadona::Checkout.new(
  'GR1' => bogo_discount,
  'SR1' => quantity_discount,
  'CF1' => bulk_discount
)

# Define order items
green_tea = Mercadona::Entity::OrderItem.new(product_code: 'GR1', name: 'Green Tea', price: 3.11)
strawberries = Mercadona::Entity::OrderItem.new(product_code: 'SR1', name: 'Strawberries', price: 5.0)
coffee = Mercadona::Entity::OrderItem.new(product_code: 'CF1', name: 'Coffee', price: 11.23)

# Add order items to checkout
[green_tea, strawberries, coffee].each { |order_item| checkout.scan(order_item) }

# Calculate total amount using current discount rules
checkout.total # => "£19.34"

Customization

You can define your custom discount logic. Please follow the example below:

require 'mercadona'

class YourCustomDiscount < Mercadona::Discount::Base
  def call
    return amount_without_discount unless discount_case?

    # Your logic here...
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bestwebua/mercadona. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct. Please check the open tickets. Be sure to follow Contributor Code of Conduct below and our Contributing Guidelines.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the mercadona project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Credits

Versioning

mercadona uses Semantic Versioning 2.0.0