Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for newer rubies #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ sudo: false
language: ruby
cache: bundler
rvm:
- 2.5.1
- 2.5
- 2.6
- 2.7
before_install:
- gem uninstall -i /home/travis/.rvm/gems/ruby-2.5.1@global bundler -x
- gem install bundler -v 2.1.4
- gem install bundler
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
> ./cc-test-reporter
Expand Down
7 changes: 7 additions & 0 deletions lib/orbf/rules_engine/builders/calculator_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def self.build(options = { nested_data_support: false, case_sensitive: true })
calculator.add_function(:between, :logical, BETWEEN)
calculator.add_function(:abs, :number, ->(number) { number.abs })
calculator.add_function(:score_table, :numeric, SCORE_TABLE)
# Dentaku now has AVG and SUM builtin, as well as ROUNDDOWN and ROUNDUP
# Their behavior is slightly different.
# AVG(1,3,9) => In our function: 4,333333
# In Dentaku: 4.0 (if one of the elements is a float, it does work the same)
#
# Since we're mostly using our go-hesabu library, I'm just keeping these as is and ignoring the
# builtin functions.
pjaspers marked this conversation as resolved.
Show resolved Hide resolved
calculator.add_function(:avg, :numeric, AVG)
calculator.add_function(:sum, :numeric, SUM)
calculator.add_function(:safe_div, :numeric, SAFE_DIV)
Expand Down
2 changes: 1 addition & 1 deletion lib/orbf/rules_engine/services/fetch_and_solve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def call
@exported_values = RulesEngine::Dhis2ValuesPrinter.new(
solver.variables,
solver.solution,
project.default_combos_ext_ids
**project.default_combos_ext_ids
).print

exported_values
Expand Down
2 changes: 1 addition & 1 deletion lib/orbf/rules_engine/value_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def attribute(attr)
end

def with(hash)
new(hash)
new(**hash)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion orbf-rules_engine.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "activesupport"
spec.add_dependency "colorize"
spec.add_dependency "hesabu"
spec.add_dependency "dentaku", "3.1.0"
spec.add_dependency "dentaku", "~> 3.3"
spec.add_dependency "dhis2", "2.3.8"
spec.add_dependency "descriptive_statistics"

Expand Down
22 changes: 11 additions & 11 deletions spec/lib/orbf/rules_engine/printers/dhis2_values_printer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
it "export no values" do
result_values = described_class.new(
[variable_without_mapping],
variable_without_mapping.key => 1.5
{ variable_without_mapping.key => 1.5 }
).print

expect(result_values).to eq([])
Expand All @@ -52,7 +52,7 @@
it "export values " do
result_values = described_class.new(
[variable_with_mapping],
variable_with_mapping.key => 1.5
{ variable_with_mapping.key => 1.5 }
).print

expect(result_values).to eq(
Expand Down Expand Up @@ -153,7 +153,7 @@ def build_package(single_mapping)
it "export no values" do
result_values = described_class.new(
[activity_variable_without_mapping],
activity_variable_without_mapping.key => 1.5
{ activity_variable_without_mapping.key => 1.5 }
).print
expect(result_values).to eq([])
end
Expand Down Expand Up @@ -191,7 +191,7 @@ def build_package(single_mapping)
it "export decimal that are actually integer as integer" do
result_values = described_class.new(
[var1, var2],
var1.key => 15, var2.key => 15
{var1.key => 15, var2.key => 15}
).print
expect(result_values).to eq(
[
Expand All @@ -218,8 +218,8 @@ def build_package(single_mapping)

result_values = described_class.new(
variables,
activity_variable_with_exportable_formula_code.key => 15.0,
exportable_variable.key => false
{ activity_variable_with_exportable_formula_code.key => 15.0,
exportable_variable.key => false }
).print

expect(result_values).to eq(
Expand All @@ -239,8 +239,8 @@ def build_package(single_mapping)

result_values = described_class.new(
variables,
activity_variable_with_exportable_formula_code.key => 15.0,
exportable_variable.key => true
{ activity_variable_with_exportable_formula_code.key => 15.0,
exportable_variable.key => true }
).print

expect(result_values).to eq(
Expand Down Expand Up @@ -300,7 +300,7 @@ def build_package(options)
formulas: [
Orbf::RulesEngine::Formula.new(
"quality_score", "31", "",
options
**options
),
Orbf::RulesEngine::Formula.new(
"exportable", "1 == 1", ""
Expand Down Expand Up @@ -367,7 +367,7 @@ def build_package(options)
def expect_exported_value(variable, solution_value, expected_value, period)
result_values = described_class.new(
[variable],
variable.key => solution_value
{ variable.key => solution_value }
).print
expect(result_values).to eq(
[
Expand Down Expand Up @@ -411,7 +411,7 @@ def build_package(options)
formulas: [
Orbf::RulesEngine::Formula.new(
"quality_score", "31", "",
options
**options
)
]
)
Expand Down