Class: MIX::Mixer
- Inherits:
-
Object
- Object
- MIX::Mixer
- Defined in:
- lib/mixer.rb
Instance Method Summary collapse
- #getResult ⇒ Object
- #getTemplate(id, path = File.dirname(__FILE__)) ⇒ Object
-
#initialize ⇒ Mixer
constructor
A new instance of Mixer.
- #mixItRuby(data, templatePath = nil) ⇒ Object
- #premix(data, templatePath) ⇒ Object
- #writeResult2File(filename) ⇒ Object
Constructor Details
#initialize ⇒ Mixer
6 7 8 9 |
# File 'lib/mixer.rb', line 6 def initialize() @result = [] @deeps = 0 end |
Instance Method Details
#getResult ⇒ Object
56 57 58 |
# File 'lib/mixer.rb', line 56 def getResult @result end |
#getTemplate(id, path = File.dirname(__FILE__)) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/mixer.rb', line 62 def getTemplate(id,path = File.dirname(__FILE__)) path = File.join(path, '../templates') filename = File.join(path,id) template = IO.read(filename) template end |
#mixItRuby(data, templatePath = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mixer.rb', line 30 def mixItRuby(data,templatePath=nil) ###putting an Index to the elements to find the sequence which has been in the json### @deeps=@deeps + 1 premix(data,templatePath) bind_hash={} data.each do |k,v| if v.kind_of?(Hash) mixItRuby(v) elsif v.kind_of?(Array) ar = v ar.each do |element| mixItRuby(element) end else #done in premix end end puts @deeps.inspect @deeps = @deeps -1 end |
#premix(data, templatePath) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mixer.rb', line 14 def premix(data,templatePath) bind_hash={} data.each do |k,v| if v.kind_of?(Hash) elsif v.kind_of?(Array) else bind_hash[k] = v end end et = ErbIT.new( bind_hash) template = getTemplate(bind_hash[:id],templatePath) filled = et.render(template) @result.push(filled) end |
#writeResult2File(filename) ⇒ Object
52 53 54 |
# File 'lib/mixer.rb', line 52 def writeResult2File(filename) File.write(filename,@result) end |