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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/compilator.rb', line 21

def notify_action(view,action,kwargs={})
  if kwargs[:location] == @model.calculatrice
    
    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 == :key_delete_pressed
      @model.delete = true
            
    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
    end
    
  elsif kwargs[:location] == @model.total
    if action == :button_calcul_pressed
      num = kwargs['a'].to_i+kwargs['c'].to_i+kwargs['e'].to_i+kwargs['g'].to_i+kwargs['i'].to_i
      denom = kwargs['b'].to_i+kwargs['d'].to_i+kwargs['f'].to_i+kwargs['h'].to_i+kwargs['j'].to_i
      @model.result_total = num.to_s+"/"+denom.to_s
      @model.result_arrondi = (num*20.to_f/denom).round(2).to_s+'/20'
    
    elsif action == :key_enter_pressed
      notify_action(view,:button_calcul_pressed,kwargs)
    
    elsif action == :button_raz_pressed
      @model.raz_total = true
    end          
  end  
  if action == :close_window 
    view.close
  end 
end