Class: Gloo::Objs::EachWord

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/objs/ctrl/each_word.rb

Constant Summary collapse

WORD =
'word'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, iterator_obj) ⇒ EachWord


Create Iterator



18
19
20
21
# File 'lib/gloo/objs/ctrl/each_word.rb', line 18

def initialize( engine, iterator_obj )
  @engine = engine
  @iterator_obj = iterator_obj
end

Class Method Details

.use_for?(iterator_obj) ⇒ Boolean

Use this iterator for each loop?

Returns:



31
32
33
34
35
# File 'lib/gloo/objs/ctrl/each_word.rb', line 31

def self.use_for?( iterator_obj )
  return true if iterator_obj.find_child WORD

  return false
end

Instance Method Details

#runObject

Run for each word.



45
46
47
48
49
50
51
52
53
# File 'lib/gloo/objs/ctrl/each_word.rb', line 45

def run
  str = @iterator_obj.in_value
  return unless str

  str.split( ' ' ).each do |word|
    set_word word
    @iterator_obj.run_do
  end
end

#set_word(word) ⇒ Object

Set the value of the word.



58
59
60
61
62
63
# File 'lib/gloo/objs/ctrl/each_word.rb', line 58

def set_word( word )
  o = @iterator_obj.find_child WORD
  return unless o

  o.set_value word
end