Class: Compilator::Compilator

Inherits:
Druzy::MVC::Controller
  • Object
show all
Defined in:
lib/compilator.rb

Instance Method Summary collapse

Constructor Details

#initialize(model = nil) ⇒ Compilator

Returns a new instance of Compilator.



11
12
13
14
15
16
17
18
19
# File 'lib/compilator.rb', line 11

def initialize(model = nil)
  if model == nil
    initialize(CompilatorModel.new)  
  else
    super(model)
    add_view(CompilatorView.new(self))
  end
  
end

Instance Method Details

#notify_action(view, action, kwargs = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/compilator.rb', line 21

def notify_action(view,action,kwargs={})
  
  if action == :key_pressed || action == :button_pressed
    model.last_key_pressed = kwargs[:key]
  
  elsif action == :key_enter_pressed
    notify_action(view,:button_equal_pressed,kwargs)
          
  elsif action == :button_equal_pressed
    numerateur = 0
    kwargs[:value].each_char do |c|
      numerateur = numerateur+model.score[c]
    end
    denominateur = kwargs[:value].size*5
    model.result = numerateur.to_s+"/"+denominateur.to_s+" => "+(numerateur*20.to_f/denominateur).round(2).to_s+"/20"
    
  elsif action == :button_raz_pressed
    model.raz = true
    
  elsif action == :close_window 
    view.close
  end 
end