Report can define and retrieve columns

This commit is contained in:
Rohan Mitchell
2015-07-23 09:52:59 +10:00
parent 0a5e8fe629
commit c7a1ca29f4
4 changed files with 56 additions and 0 deletions

View File

@@ -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

View 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