mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Report can define and retrieve columns
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
require 'open_food_network/reports/row'
|
||||
|
||||
module OpenFoodNetwork::Reports
|
||||
class Report
|
||||
# -- API
|
||||
@@ -5,10 +7,19 @@ module OpenFoodNetwork::Reports
|
||||
@@header
|
||||
end
|
||||
|
||||
def columns
|
||||
@@columns.to_a
|
||||
end
|
||||
|
||||
|
||||
# -- DSL
|
||||
def self.header(*columns)
|
||||
@@header = columns
|
||||
end
|
||||
|
||||
def self.columns(&block)
|
||||
@@columns = Row.new
|
||||
@@columns.instance_eval(&block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
16
lib/open_food_network/reports/row.rb
Normal file
16
lib/open_food_network/reports/row.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module OpenFoodNetwork::Reports
|
||||
class Row
|
||||
def initialize
|
||||
@columns = []
|
||||
end
|
||||
|
||||
|
||||
def column(&block)
|
||||
@columns << block
|
||||
end
|
||||
|
||||
def to_a
|
||||
@columns
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user