Class: Mikyung

Inherits:
Object
  • Object
show all
Defined in:
lib/mikyung.rb

Overview

iterates following a series of steps provided a goal and a starting uri.

Mikyung.new(objective).run(uri)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Mikyung

initializes with a goal in mind



49
50
51
52
# File 'lib/mikyung.rb', line 49

def initialize(*args)
  @goal = args[0]
  @start = args[1] if args.size==2
end

Instance Attribute Details

#goalObject (readonly)

Returns the value of attribute goal.



46
47
48
# File 'lib/mikyung.rb', line 46

def goal
  @goal
end

#startObject (readonly)

Returns the value of attribute start.



46
47
48
# File 'lib/mikyung.rb', line 46

def start
  @start
end

Instance Method Details

#run(*args) ⇒ Object

keeps changing from a steady state to another until its goal has been achieved



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mikyung.rb', line 55

def run(*args)
  
  @start = current = @start || Restfulie.at(args[0]).get
  Restfulie::Common::Logger.logger.debug current.response.body
  
  while(!@goal.completed?(current))
    step = @goal.next_step(current)
    raise "No step was found for #{current} with links #{current.links}" unless step
    Restfulie::Common::Logger.logger.debug "Mikyung > next step will be #{step}"
    step = step.new if step.kind_of? Class
    current = try_to_execute(step, current, 3)
  end
  
end