Class: HSpreadFieldTable

Inherits:
HFieldTable show all
Defined in:
lib/hdatastructures/hspreadfieldtable.rb

Direct Known Subclasses

HSqlTable

Instance Attribute Summary collapse

Attributes inherited from HFieldTable

#allCols, #allRows, #tableName

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HFieldTable

#[], #addFieldName, #columnCount, #columnCountByKey, #copyConstructor, #data, #deleteRow, #each, #eachWithFieldName, #fields, #insertRow, #match, #method_missing, #row, #rowCount, #rowWithFieldName, #setCaption, #setData, #setDataByFieldName, #setIntoRecordByFieldName, #show, #showData, #showHeader, #showTotalizers, #sortBy, #sumByFieldName, #valueByFieldName, #valueByType

Methods inherited from Array

#<, #addIfNotPresent, #column, #filter, #herbertsort, #herbertsort!, #hjoin, #hpartition, #show, #sortByList, #sortByPositionList, #swap, #to_js_format

Constructor Details

#initializeHSpreadFieldTable

Returns a new instance of HSpreadFieldTable.



9
10
11
12
13
# File 'lib/hdatastructures/hspreadfieldtable.rb', line 9

def initialize
  super
  @decorator = false
  @summaryList = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HFieldTable

Instance Attribute Details

#decoratorObject

Returns the value of attribute decorator.



6
7
8
# File 'lib/hdatastructures/hspreadfieldtable.rb', line 6

def decorator
  @decorator
end

#summaryListObject (readonly)

Returns the value of attribute summaryList.



7
8
9
# File 'lib/hdatastructures/hspreadfieldtable.rb', line 7

def summaryList
  @summaryList
end

Class Method Details

.testObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# 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

.test2Object



113
114
115
116
117
118
119
120
121
122
# 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

Instance Method Details

#addSummary(summaryName, summaryValue) ⇒ Object



15
16
17
18
19
20
21
22
# 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) ⇒ Object



43
44
45
46
47
48
49
50
# 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) ⇒ Object



28
29
30
31
32
# 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) ⇒ Object



34
35
36
37
38
39
40
41
# 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) ⇒ Object



24
25
26
# File 'lib/hdatastructures/hspreadfieldtable.rb', line 24

def noname(data, value)
  return data.class == HRecord ? data.dup.setValue(value) : value
end

#showSummaryObject



52
53
54
55
56
57
58
59
60
61
# 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