class HSpreadFieldTable
Attributes
decorator[RW]
summaryList[R]
Public Class Methods
new()
click to toggle source
Calls superclass method
HFieldTable::new
# File lib/hdatastructures/hspreadfieldtable.rb, line 9 def initialize super @decorator = false @summaryList = [] end
test()
click to toggle source
# File lib/hdatastructures/hspreadfieldtable.rb, line 64 def self.test() fieldTable = HSpreadFieldTable.new() fieldTable.addFieldName("quantity") fieldTable.addFieldName("description") fieldTable.addFieldName("price") fieldTable.addFieldName("amount", false) fieldTable.addFieldName("score") fieldTable.addFieldName("other") fieldTable.setFieldCaption("quantity", "Quantity") fieldTable.setFieldCaption("description", "Description") fieldTable.setFieldCaption("price", "Price") fieldTable.setFieldCaption("amount", "Amount") fieldTable.setFieldCaption("score", "Score") fieldTable.setFieldCaption("other", "Other") fieldTable.setFieldFilter("price", 3) fieldTable.setFieldFilter("score", HRecord.new(18)) fieldTable.setFieldDecorator("description", "Item: §arg§") fieldTable.setFieldTotalizer("price", "P R I C E") fieldTable.setFieldTotalizer("amount", "T O T A L") fieldTable.setFieldTotalizer("score", "S C O R E") fieldTable.addSummary("SUMMARY", "2.000 Euro") for i in 0..5 (other = HRecord.new(i)).color = "green" (amount = HRecord.new("`quantity * `price")).color = "yellow" fieldTable.setIntoRecordByFieldName(i, "quantity", i) fieldTable.setIntoRecordByFieldName(i, "description", "Product #{i}") fieldTable.setIntoRecordByFieldName(i, "price", i) fieldTable.setDataByFieldName(i, "amount", amount) fieldTable.setIntoRecordByFieldName(i, "score", "`amount * 2") fieldTable.setDataByFieldName(i, "other", other) end fieldTable.show() fieldTable.allRows,fieldTable.allCols = true, true fieldTable.decorator = true fieldTable.show() fieldTable.showTotalizers() fieldTable.showSummary() return fieldTable end
test2()
click to toggle source
# File lib/hdatastructures/hspreadfieldtable.rb, line 113 def self.test2 fieldTable = HSpreadFieldTable.test() fieldTable.eachWithFieldName do |row| row.each do |key, data| p key, data end puts end return fieldTable end
Public Instance Methods
addSummary(summaryName, summaryValue)
click to toggle source
# File lib/hdatastructures/hspreadfieldtable.rb, line 15 def addSummary(summaryName, summaryValue) record = HRecord.new(summaryName) record.setValue(summaryName) record.set(:value, summaryValue) @summaryList << record end
dataByFieldName(row, fieldName)
click to toggle source
Calls superclass method
HFieldTable#dataByFieldName
# File lib/hdatastructures/hspreadfieldtable.rb, line 43 def dataByFieldName(row, fieldName) value = data = super(row, fieldName) value = data.value() if (data.class == HRecord) return self.noname(data, self.evalDataByFieldName(row, fieldName)) if value.class == String and value.index('`') return self.decorate(data, value, fieldName) end
decorate(data, value, fieldName)
click to toggle source
# File lib/hdatastructures/hspreadfieldtable.rb, line 28 def decorate(data, value, fieldName) decorator = @fields[fieldName].decorator value = decorator.gsub("§arg§", value) if (@decorator and decorator) return self.noname(data, value) end
evalDataByFieldName(row, fieldName)
click to toggle source
# File lib/hdatastructures/hspreadfieldtable.rb, line 34 def evalDataByFieldName(row, fieldName) value = self.valueByFieldName(row, fieldName) return value if value.class == Fixnum value = value.gsub(/`([a-zA-Z_]+[a-zA-Z_0-9]*)/) { |var| self.evalDataByFieldName(row, $1) } return eval(value) end
noname(data, value)
click to toggle source
# File lib/hdatastructures/hspreadfieldtable.rb, line 24 def noname(data, value) return data.class == HRecord ? data.dup.setValue(value) : value end
showSummary()
click to toggle source
# File lib/hdatastructures/hspreadfieldtable.rb, line 52 def showSummary() @summaryList.each do |data| if data print $hpformat % data.value() print $hpformat % data.value(:value) end puts end end