Class: Demos::Counter

Inherits:
Hokusai::Block show all
Defined in:
ui/examples/counter.rb

Instance Attribute Summary collapse

Attributes inherited from Hokusai::Block

#node, #provides, #publisher

Instance Method Summary collapse

Methods inherited from Hokusai::Block

#children, #children?, compile, computed, computed!, #draw, #draw_with, #dump, #emit, inject, inject!, #method_missing, mount, #on_resize, provide, provides, #render, style, styles_get, template, template_from_file, template_get, #update, use, uses

Constructor Details

#initialize(**args) ⇒ Counter

Returns a new instance of Counter.



99
100
101
102
103
# File 'ui/examples/counter.rb', line 99

def initialize(**args)
  @count = 0
  @keys = ""
  super(**args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hokusai::Block

Instance Attribute Details

#countObject

Returns the value of attribute count.



73
74
75
# File 'ui/examples/counter.rb', line 73

def count
  @count
end

#keysObject

Returns the value of attribute keys.



73
74
75
# File 'ui/examples/counter.rb', line 73

def keys
  @keys
end

Instance Method Details

#count_colorObject



95
96
97
# File 'ui/examples/counter.rb', line 95

def count_color
  self.count > 0 ? [0,0,255] : [255,0,0]
end

#count_positiveObject



75
76
77
# File 'ui/examples/counter.rb', line 75

def count_positive
  count > 0
end

#decrement(event) ⇒ Object



91
92
93
# File 'ui/examples/counter.rb', line 91

def decrement(event)
  self.count -= 1
end

#increment(event) ⇒ Object



87
88
89
# File 'ui/examples/counter.rb', line 87

def increment(event)
  self.count += 1
end


79
80
81
# File 'ui/examples/counter.rb', line 79

def modal
  !keys.empty?
end

#update_keys(event) ⇒ Object



83
84
85
# File 'ui/examples/counter.rb', line 83

def update_keys(event)
  @keys << event.char
end