Class: InternetHakai::Scenario
- Inherits:
-
Object
- Object
- InternetHakai::Scenario
- Defined in:
- lib/internethakai/scenario.rb
Overview
シナリオ
Instance Attribute Summary collapse
-
#actions_size ⇒ Object
readonly
Returns the value of attribute actions_size.
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#performance_id ⇒ Object
Returns the value of attribute performance_id.
-
#scenario_id ⇒ Object
Returns the value of attribute scenario_id.
-
#vars ⇒ Object
Returns the value of attribute vars.
Instance Method Summary collapse
- #create_act(idx) ⇒ Object
- #create_scenario ⇒ Object
- #each(&block) ⇒ Object
- #init ⇒ Object
-
#initialize(opt) ⇒ Scenario
constructor
A new instance of Scenario.
- #next ⇒ Object
- #set_cookie(cookie) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(opt) ⇒ Scenario
Returns a new instance of Scenario.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/internethakai/scenario.rb', line 4 def initialize(opt) @config = opt @size = 0 @actions_size @performance_id = nil @scenario_id = nil @loop = @config['loop'] @loop_org = @loop digit = @loop.to_s.size @tmpl = "%0#{digit}d" @request_pool = BaseHandler::get_handler(@config['request_pool']) #@page_size = [10, @loop].min @page_size = 1 @page = (@loop.quo(@page_size)).ceil @page_counter = @page @vars = {} @cookie = {} end |
Instance Attribute Details
#actions_size ⇒ Object (readonly)
Returns the value of attribute actions_size.
23 24 25 |
# File 'lib/internethakai/scenario.rb', line 23 def actions_size @actions_size end |
#cookie ⇒ Object
Returns the value of attribute cookie.
24 25 26 |
# File 'lib/internethakai/scenario.rb', line 24 def @cookie end |
#performance_id ⇒ Object
Returns the value of attribute performance_id.
24 25 26 |
# File 'lib/internethakai/scenario.rb', line 24 def performance_id @performance_id end |
#scenario_id ⇒ Object
Returns the value of attribute scenario_id.
24 25 26 |
# File 'lib/internethakai/scenario.rb', line 24 def scenario_id @scenario_id end |
#vars ⇒ Object
Returns the value of attribute vars.
24 25 26 |
# File 'lib/internethakai/scenario.rb', line 24 def vars @vars end |
Instance Method Details
#create_act(idx) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/internethakai/scenario.rb', line 97 def create_act idx actconf = @actconfigs[idx] obj = actconf['class_obj']::new(actconf) obj.set_scenario(self) obj end |
#create_scenario ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/internethakai/scenario.rb', line 66 def create_scenario @commands = [] @performance_id = (@scenario_id.to_s + sprintf(@tmpl, @loop)).to_i @actions_size = @config['actions'].inject(0){|sum, i| times = i['times'] sum + times } baseconfig = @config.clone baseconfig.delete('actions') 1.upto(@page_size){ @config["actions"].each do |actconfig| actconfig = baseconfig.merge(actconfig) times = actconfig['times'] command = actconfig['class_obj'] 1.upto(times) do actconfignew = actconfig.clone obj = command.new(actconfignew, self) obj.set_wait if(actconfignew['wait']) @commands << obj end end } @action_counter = @actions_size @commands_org = @commands.clone @size = @actions_size * @loop_org end |
#each(&block) ⇒ Object
61 62 63 64 65 |
# File 'lib/internethakai/scenario.rb', line 61 def each &block @commands_org.each do |cm| block.call(cm) end end |
#init ⇒ Object
28 29 30 31 32 33 |
# File 'lib/internethakai/scenario.rb', line 28 def init @performance_id = (@scenario_id.to_s + sprintf(@tmpl, @loop)).to_i act = @commands.shift act.performance_id = @performance_id @request_pool.add(act) end |
#next ⇒ Object
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 |
# File 'lib/internethakai/scenario.rb', line 34 def next @action_counter -= 1 #puts "action: #{@action_counter}" #puts "loop: #{@loop}" if @action_counter == 0 @loop -= 1 #これで最後 if @loop == 0 if @config['infinity'] @loop += 100 # 無限ループ! else return end end @action_counter = @actions_size @performance_id = (@scenario_id.to_s + sprintf(@tmpl, @loop)).to_i end if @commands.empty? #ループが残っていればまた最初から @commands = @commands_org.clone @cookie = {} @vars = {} end act = @commands.shift act.performance_id = @performance_id @request_pool.add(act) end |
#set_cookie(cookie) ⇒ Object
92 93 94 95 96 |
# File 'lib/internethakai/scenario.rb', line 92 def return unless k, v = [0....index(';')].split('=') @cookie[k] = v if k && v end |
#size ⇒ Object
25 26 27 |
# File 'lib/internethakai/scenario.rb', line 25 def size @size end |