mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Report outputs rules as array for use by OrderGrouper
This commit is contained in:
@@ -12,6 +12,19 @@ module OpenFoodNetwork::Reports
|
||||
@@columns.to_a
|
||||
end
|
||||
|
||||
def rules
|
||||
# Flatten linked list and return as hashes
|
||||
rules = []
|
||||
|
||||
rule = @@rules_head
|
||||
while rule
|
||||
rules << rule
|
||||
rule = rule.next
|
||||
end
|
||||
|
||||
rules.map &:to_h
|
||||
end
|
||||
|
||||
|
||||
# -- DSL
|
||||
def self.header(*columns)
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
require 'open_food_network/reports/report'
|
||||
|
||||
module OpenFoodNetwork::Reports
|
||||
P1 = Proc.new { |o| o[:one] }
|
||||
P2 = Proc.new { |o| o[:two] }
|
||||
P3 = Proc.new { |o| o[:three] }
|
||||
P4 = Proc.new { |o| o[:four] }
|
||||
|
||||
class TestReport < Report
|
||||
header 'One', 'Two', 'Three', 'Four'
|
||||
|
||||
columns do
|
||||
column { |o| o[:one] }
|
||||
column { |o| o[:two] }
|
||||
column { |o| o[:three] }
|
||||
column { |o| o[:four] }
|
||||
column &P1
|
||||
column &P2
|
||||
column &P3
|
||||
column &P4
|
||||
end
|
||||
|
||||
organise do
|
||||
group { |o| o[:one] }
|
||||
sort { |o| o[:two] }
|
||||
group &P1
|
||||
sort &P2
|
||||
|
||||
organise do
|
||||
group { |o| o[:three] }
|
||||
sort { |o| o[:four] }
|
||||
group &P3
|
||||
sort &P4
|
||||
|
||||
summary_row do
|
||||
column { |o| o[:one] }
|
||||
column { |o| o[:four] }
|
||||
column &P1
|
||||
column &P4
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -65,5 +70,12 @@ module OpenFoodNetwork::Reports
|
||||
next_summary_columns[1].call(data).should == 4
|
||||
end
|
||||
end
|
||||
|
||||
describe "outputting rules" do
|
||||
it "outputs the rules" do
|
||||
report.rules.should == [{group_by: P1, sort_by: P2},
|
||||
{group_by: P3, sort_by: P4, summary_columns: [P1, P4]}]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user