Class: Step

Inherits:
Object
  • Object
show all
Defined in:
lib/completion-progress/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, options = {}, &block) ⇒ Step

Returns a new instance of Step.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/completion-progress/step.rb', line 6

def initialize(name, value, options = {}, &block)
  @name = name
  @value = value
  @block = block
  @result = false

  if (options.has_key?(:hint))
    @hint = Hint.new(self, options[:hint][:text], options[:hint][:href], options[:hint][:options])
  else
    @hint = Hint.new(self, "Fill #{name}")
  end
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



4
5
6
# File 'lib/completion-progress/step.rb', line 4

def block
  @block
end

#hintObject

Returns the value of attribute hint.



4
5
6
# File 'lib/completion-progress/step.rb', line 4

def hint
  @hint
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/completion-progress/step.rb', line 4

def name
  @name
end

#resultObject

Returns the value of attribute result.



4
5
6
# File 'lib/completion-progress/step.rb', line 4

def result
  @result
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/completion-progress/step.rb', line 4

def value
  @value
end

Instance Method Details

#process(obj) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/completion-progress/step.rb', line 19

def process(obj)
  begin

    if !@block
      val = obj.send(@name)
    else
      val = obj.instance_eval(&@block)
    end

    if val.kind_of?(Array) or val.kind_of?(Hash)
      @result = val.count == 0 ? false : true
    else
      @result = val
    end

  rescue Exception => e
    @result = false
  ensure
    @result ? @result = true : @result = false
  end
end