Class: Twb::FieldCalculation
- Inherits:
-
Object
- Object
- Twb::FieldCalculation
- Defined in:
- lib/twb/fieldcalculation.rb
Instance Attribute Summary collapse
-
#class ⇒ Object
readonly
Returns the value of attribute class.
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#formula ⇒ Object
readonly
Returns the value of attribute formula.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #getComments(lines) ⇒ Object
- #getFormula(lines) ⇒ Object
-
#initialize(calcNode) ⇒ FieldCalculation
constructor
A new instance of FieldCalculation.
- #parseFieldsFromFormula(formula) ⇒ Object
Constructor Details
#initialize(calcNode) ⇒ FieldCalculation
Returns a new instance of FieldCalculation.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/twb/fieldcalculation.rb', line 24 def initialize calcNode #puts "CALCNODE:: '#{calcNode}' -> #{calcNode.class}" if calcNode @node = calcNode #-- Calculation -- formulaCode = calcNode.xpath('./@formula').text.gsub(/\r\n/, ' ') formulaLines = calcNode.xpath('./@formula').text.split(/\r\n/) @formula = getFormula( formulaLines ) @comments = getComments( formulaLines ) @class = calcNode.xpath('./@class').text @scopeIsolation = calcNode.xpath('./@scope-isolation').text #-- Fields -- @fields = parseFieldsFromFormula(formulaCode) end end |
Instance Attribute Details
#class ⇒ Object (readonly)
Returns the value of attribute class.
22 23 24 |
# File 'lib/twb/fieldcalculation.rb', line 22 def class @class end |
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
22 23 24 |
# File 'lib/twb/fieldcalculation.rb', line 22 def comments @comments end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
22 23 24 |
# File 'lib/twb/fieldcalculation.rb', line 22 def fields @fields end |
#formula ⇒ Object (readonly)
Returns the value of attribute formula.
22 23 24 |
# File 'lib/twb/fieldcalculation.rb', line 22 def formula @formula end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
22 23 24 |
# File 'lib/twb/fieldcalculation.rb', line 22 def node @node end |
Instance Method Details
#getComments(lines) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/twb/fieldcalculation.rb', line 62 def getComments lines comments = '' lines.each do |line| if line =~ /\/\// then comments += ' ' + line.gsub(/^.*\/\//,'// ') end end return comments.strip end |
#getFormula(lines) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/twb/fieldcalculation.rb', line 53 def getFormula lines formula = '' lines.each do |line| line.strip formula += ' ' + line.gsub(/\/\/.*/, '') # unless line =~ /^[ ]*\/\// end return formula.strip end |
#parseFieldsFromFormula(formula) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/twb/fieldcalculation.rb', line 40 def parseFieldsFromFormula formula fieldSet = Set.new [] if formula =~ /\[.+\]/ then stripFrt = formula.gsub( /^[^\[]*[\[]/ , '[' ) stripBck = stripFrt.gsub( /\][^\]]+$/ , ']' ) stripMid = stripBck.gsub( /\][^\]]{2,}\[/ , ']]..[[' ) stripCom = stripMid.gsub( /\][ ]*,[ ]*\[/ , ']]..[[' ) fields = stripCom.split(']..[') fields.each { |field| fieldSet.add field} end return fieldSet end |