根据规则计算价格(红宝石规则引擎) [英] Calculating Prices based on Rules (Ruby Rule Engine)

查看:783
本文介绍了根据规则计算价格(红宝石规则引擎)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一对夫妇的规则引擎,如树顶或Wongi ::引擎,但没有似乎适合我的个人资料。

there are a couple of rule engines like Treetop or Wongi::Engine, but none seem to fit my profile.

我想打造的是一个灵活的系统,它可以计算出价格。对于例如:

i want to build is a flexible system which can calculate prices. for e.g:

基本价格是100€一个雪橇

Base Price is 100€ for a sled

产品规则:

Product Rule:

  • Rule_#0雪橇费100€

时间规则:

Time Rule:

  • Rule_#1您将于23:00后买了雪橇=>你获得10€的折扣

日期规则:

Date Rule:

  • Rule_#2你买的雪橇上的圣诞=>你得到10%的折扣(10€)

用户规则:

User Rule:

  • Rule_#3你的名字是圣诞老人=>你得到2€的折扣

规则也可以合并(不包括/包括):

Rules can also be combined (exclude/include):

=>最终价格100-10-10-2 = 78

=> Final Price is 100-10-10-2=78

推荐答案

AFAIK,没有捷径来解决你的问题。

AFAIK, there is no short-cut to solve your problem.

的价格规则引擎需要知道底层模型,并能够引用它。一般最短,效率最高code做这些事情已经存在于如的ActiveResource或DataMapper的。你能想出的任何规则将直接在Ruby中code,它操纵的模型pssed最容易EX $ P $。使更多的抽象,通过DSL的价格,是超过你将单独建立的规则上更多的工作。一个pre的DSL产品定价不存在pre封装电子商务解决方案(数据模型是已知的)之外。

The price rules engine needs to know the underlying model, and be able to reference it. Generally the shortest, most efficient code to do these things already exists in e.g. ActiveResource or DataMapper. Any rules you could come up with will be most easily expressed directly in Ruby code that manipulates that model. Making that more abstract, via a DSL for pricing, is more work over the top of the rules you will be individually building. A pre-built DSL for product pricing does not exist outside of pre-packaged e-Commerce solutions (where the data model is known).

您可能正在寻找一个面向对象的设计模式,而不是一个宝石或库。你有你很多的工作要做。

You are probably looking for an object-oriented design pattern, not a gem or library. And you have a lot of work ahead of you.

这篇关于根据规则计算价格(红宝石规则引擎)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆