smalruby-editor 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of smalruby-editor might be problematic. Click here for more details.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/Guardfile +8 -1
  4. data/app/assets/javascripts/blocks/hardware.js.coffee.erb +11 -152
  5. data/app/assets/javascripts/msg/en_us.js +5 -5
  6. data/app/assets/javascripts/msg/ja.js +5 -5
  7. data/app/assets/javascripts/views/signin_modal_view.js.coffee.erb +0 -0
  8. data/app/controllers/sessions_controller.rb +0 -0
  9. data/app/helpers/sessions_helper.rb +4 -0
  10. data/app/models/concerns/ruby_to_block/block/hardware_operation.rb +11 -0
  11. data/app/models/concerns/ruby_to_block/block/{hardware_smalrubot_s1_led_turn_on_or_off.rb → hardware_smalrubot_action.rb} +8 -5
  12. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_action_with_sec.rb +25 -0
  13. data/app/models/concerns/ruby_to_block/block/{hardware_smalrubot_v3_motor_speed.rb → hardware_smalrubot_dc_motor_power_ratio.rb} +8 -5
  14. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_dc_motor_set_power_ratio.rb +23 -0
  15. data/app/models/concerns/ruby_to_block/block/{hardware_smalrubot_v3_led_turn_on_or_off.rb → hardware_smalrubot_led_turn_on_or_off.rb} +8 -5
  16. data/app/models/concerns/ruby_to_block/block/{hardware_smalrubot_s1_ir_photoreflector_value.rb → hardware_smalrubot_sensor_value.rb} +8 -6
  17. data/app/views/editor/_toolbox_default.html.haml +4 -7
  18. data/app/views/editor/index.html.haml +7 -18
  19. data/bin/spring +0 -0
  20. data/config/application.rb +1 -0
  21. data/lib/smalruby_editor/version.rb +1 -1
  22. data/smalruby-editor.gemspec +1 -1
  23. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_s1_led_turn_on_or_off.feature +8 -8
  24. data/spec/acceptance/block_mode/blocks/hardware/{smalrubot_v3_motor_speed.feature → smalrubot_v3_dc_motor_power_ratio.feature} +12 -12
  25. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_led_turn_on_or_off.feature +8 -8
  26. data/spec/acceptance/block_mode/blocks/hardware/{smalrubot_s1_ir_photoreflector_value.feature → smalrubot_v3_sensor_value.feature} +7 -7
  27. data/spec/models/concerns/ruby_to_block/block/{hardware__smalrubot_s1_spec.rb → hardware__smalrubot_spec.rb} +88 -84
  28. data/spec/spec_helper.rb +0 -0
  29. data/spec/steps/base_steps.rb +0 -0
  30. data/spec/steps/text_editor_steps.rb +0 -0
  31. metadata +23 -36
  32. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_action.rb +0 -13
  33. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_action_with_sec.rb +0 -14
  34. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_dc_motor_power_ratio.rb +0 -26
  35. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_s1_dc_motor_set_power_ratio.rb +0 -21
  36. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_action.rb +0 -22
  37. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_action_with_sec.rb +0 -24
  38. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_light_sensor_value.rb +0 -28
  39. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_motor_set_speed.rb +0 -21
  40. data/app/models/concerns/ruby_to_block/block/hardware_smalrubot_v3_touch_sensor_pressed_or_released.rb +0 -29
  41. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_light_sensor_value.feature +0 -92
  42. data/spec/acceptance/block_mode/blocks/hardware/smalrubot_v3_touch_sensor_pressed_or_released.feature +0 -108
  43. data/spec/models/concerns/ruby_to_block/block/hardware__smalrubot_v3_spec.rb +0 -433
@@ -1,19 +1,22 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module RubyToBlock
3
3
  module Block
4
- class HardwareSmalrubotV3LedTurnOnOrOff < CharacterMethodCall
4
+ class HardwareSmalrubotLedTurnOnOrOff < CharacterMethodCall
5
5
  include HardwareOperation
6
6
 
7
7
  # rubocop:disable LineLength
8
- blocknize '^\s*' + CHAR_RE +
9
- 'smalrubot_v3\.(red|green)_led.(turn_on|turn_off)' +
10
- '\s*$',
8
+ blocknize ['^\s*',
9
+ CHAR_RE,
10
+ SMALRUBOT_RE, '\.',
11
+ ON_OFF_RE, '_', LOR_RE, '_led',
12
+ '\s*$'].join(''),
11
13
  statement: true, inline: true
12
14
  # rubocop:enable LineLength
13
15
 
14
16
  def self.process_match_data(md, context)
15
17
  md2 = regexp.match(md[type])
16
- block = new(fields: { COLOUR: md2[2], OOO: md2[3] })
18
+ block = new(fields: { LOR: md2[4], OOO: md2[3] })
19
+ block.smalrubot_name = md2[2]
17
20
  add_character_method_call_block(context, md2[1], block)
18
21
  true
19
22
  end
@@ -1,14 +1,15 @@
1
1
  module RubyToBlock
2
2
  module Block
3
- class HardwareSmalrubotS1IrPhotoreflectorValue < Value
3
+ class HardwareSmalrubotSensorValue < Value
4
4
  include CharacterOperation
5
5
  include HardwareOperation
6
6
 
7
7
  # rubocop:disable LineLength
8
- blocknize '^\s*' + CHAR_RE +
9
- 'smalrubot_s1\.' +
10
- LOR_RE + '_ir_photoreflector_value' +
11
- '\s*$',
8
+ blocknize ['^\s*',
9
+ CHAR_RE,
10
+ SMALRUBOT_RE, '.',
11
+ LOR_RE, '_sensor_value',
12
+ '\s*$'].join(''),
12
13
  value: true
13
14
  # rubocop:enable LineLength
14
15
 
@@ -18,7 +19,8 @@ module RubyToBlock
18
19
  character = get_character(context, md2[1])
19
20
  return false if context.receiver && context.receiver != character
20
21
 
21
- block = new(fields: { LOR: md2[2] })
22
+ block = new(fields: { LOR: md2[3] })
23
+ block.smalrubot_name = md2[2]
22
24
  context.add_value(block)
23
25
  block.character = character
24
26
 
@@ -146,7 +146,7 @@
146
146
  forward
147
147
  = toolbox_number_value('SEC', 0.5)
148
148
 
149
- %block{type: "#{category}_#{subcategory}_motor_set_speed"}
149
+ %block{type: "#{category}_#{subcategory}_dc_motor_set_power_ratio"}
150
150
  = toolbox_number_value('SPEED', 100)
151
151
 
152
152
  - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_s1_blocks_on_default')
@@ -240,8 +240,6 @@
240
240
  - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_v3_blocks_on_default')
241
241
  - subcategory = 'smalrubot_v3'
242
242
  %block{type: "#{category}_#{subcategory}_led_turn_on_or_off"}
243
- %field{name: 'COLOUR'}<
244
- red
245
243
  %field{name: 'OOO'}<
246
244
  turn_on
247
245
 
@@ -395,14 +393,13 @@
395
393
 
396
394
  - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_v3_blocks_on_default')
397
395
  - subcategory = 'smalrubot_v3'
398
- %block{type: "#{category}_#{subcategory}_touch_sensor_pressed_or_released"}
399
- %block{type: "#{category}_#{subcategory}_light_sensor_value"}
400
- %block{type: "#{category}_#{subcategory}_motor_speed"}
396
+ %block{type: "#{category}_#{subcategory}_sensor_value"}
397
+ %block{type: "#{category}_#{subcategory}_dc_motor_power_ratio"}
401
398
 
402
399
  - if SmalrubyEditor::Config.enabled?('enabled_smalrubot_s1_blocks_on_default')
403
400
  - category = 'hardware'
404
401
  - subcategory = 'smalrubot_s1'
405
- %block{type: "#{category}_#{subcategory}_ir_photoreflector_value"}
402
+ %block{type: "#{category}_#{subcategory}_sensor_value"}
406
403
  %block{type: "#{category}_#{subcategory}_dc_motor_power_ratio"}
407
404
 
408
405
  - category = 'operators'
@@ -43,14 +43,9 @@
43
43
  %i.icon-off
44
44
  = t('.reset')
45
45
  - if standalone?
46
- - if session[:username]
47
- %button#signout-button.btn{class: "btn-primary"}<
48
- %i.icon-eject
49
- = t('.logout')
50
- - else
51
- %button#signout-button.btn{class: "btn-primary", style: "display: none"}<
52
- %i.icon-eject
53
- = t('.logout')
46
+ %button#signout-button.btn{class: "btn-primary", style: "display: #{signed_in? ? '' : 'none'}"}<
47
+ %i.icon-eject
48
+ = t('.logout')
54
49
 
55
50
  - else
56
51
  .btn-group
@@ -84,16 +79,10 @@
84
79
  = t('.reset')
85
80
  - if standalone?
86
81
  %li
87
- - if session[:username]
88
- %a#signout-button
89
- %h4
90
- %i.icon-eject
91
- = t('.logout')
92
- - else
93
- %a#signout-button{style: "display: none"}
94
- %h4
95
- %i.icon-eject
96
- = t('.logout')
82
+ %a#signout-button{style: "display: #{signed_in? ? '' : 'none'}"}
83
+ %h4
84
+ %i.icon-eject
85
+ = t('.logout')
97
86
 
98
87
  - if standalone?
99
88
  - if session[:username]
data/bin/spring CHANGED
File without changes
@@ -10,6 +10,7 @@ Bundler.require(:default, Rails.env) unless Rails.env == 'standalone'
10
10
  module SmalrubyEditor
11
11
  class Application < Rails::Application
12
12
  config.time_zone = 'Tokyo'
13
+ I18n.enforce_available_locales = true
13
14
  config.i18n.default_locale = :ja
14
15
  config.colorize_logging = false
15
16
  config.filter_parameters += [:data]
@@ -1,3 +1,3 @@
1
1
  module SmalrubyEditor
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
@@ -69,7 +69,7 @@ Gem::Specification.new do |spec|
69
69
  ['haml-rails'],
70
70
  ['nokogiri'],
71
71
  ['settingslogic'],
72
- ['smalruby', '~> 0.1.4'],
72
+ ['smalruby', '~> 0.1.6'],
73
73
  ]
74
74
  runtime_dependencies << ['therubyracer'] unless is_windows
75
75
  runtime_dependencies.each do |args|
@@ -10,8 +10,8 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
10
10
  When 次のブロックを配置する:
11
11
  """
12
12
  %block{:type => "hardware_smalrubot_s1_led_turn_on_or_off", :x => "0", :y => "0"}
13
- %field{:name => "COLOUR"}<
14
- white
13
+ %field{:name => "LOR"}<
14
+ right
15
15
  %field{:name => "OOO"}<
16
16
  turn_off
17
17
  """
@@ -27,8 +27,8 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
27
27
  car1
28
28
  %statement{:name => "DO"}
29
29
  %block{:type => "hardware_smalrubot_s1_led_turn_on_or_off", :x => "0", :y => "0"}
30
- %field{:name => "COLOUR"}<
31
- white
30
+ %field{:name => "LOR"}<
31
+ right
32
32
  %field{:name => "OOO"}<
33
33
  turn_off
34
34
  """
@@ -39,7 +39,7 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
39
39
  require "smalruby"
40
40
 
41
41
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
42
- car1.smalrubot_s1.turn_off_white_led
42
+ car1.smalrubot_s1.turn_off_right_led
43
43
 
44
44
  """
45
45
 
@@ -53,8 +53,8 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
53
53
  %block{:type => "events_on_start"}
54
54
  %statement{:name => "DO"}
55
55
  %block{:type => "hardware_smalrubot_s1_led_turn_on_or_off", :x => "0", :y => "0"}
56
- %field{:name => "COLOUR"}<
57
- blue
56
+ %field{:name => "LOR"}<
57
+ left
58
58
  %field{:name => "OOO"}<
59
59
  turn_on
60
60
  """
@@ -67,7 +67,7 @@ Feature: hardware_smalrubot_s1_led_turn_on_or_off block
67
67
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
68
68
 
69
69
  car1.on(:start) do
70
- smalrubot_s1.turn_on_blue_led
70
+ smalrubot_s1.turn_on_left_led
71
71
  end
72
72
 
73
73
  """
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # language: en
3
3
  @javascript
4
- Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
4
+ Feature: hardware_smalrubot_v3_dc_motor_{,set_}power_ratio block
5
5
  Background:
6
6
  Given "ブロック" タブを表示する
7
7
  And キャラクターcar1を追加する
@@ -9,7 +9,7 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
9
9
  Scenario: ブロックのみ配置する
10
10
  When 次のブロックを配置する:
11
11
  """
12
- %block{:type => "hardware_smalrubot_v3_motor_speed"}
12
+ %block{:type => "hardware_smalrubot_v3_dc_motor_power_ratio"}
13
13
  %field{:name => "LOR"}<
14
14
  right
15
15
  """
@@ -22,11 +22,11 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
22
22
  """
23
23
  %block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
24
24
  %value{:name => "ARG"}
25
- %block{:type => "hardware_smalrubot_v3_motor_speed"}
25
+ %block{:type => "hardware_smalrubot_v3_dc_motor_power_ratio"}
26
26
  %field{:name => "LOR"}<
27
27
  right
28
28
  %next
29
- %block{:type => "hardware_smalrubot_v3_motor_set_speed"}
29
+ %block{:type => "hardware_smalrubot_v3_dc_motor_set_power_ratio"}
30
30
  %field{:name => "LOR"}<
31
31
  left
32
32
  %value{:name => "SPEED"}
@@ -53,11 +53,11 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
53
53
  %statement{:name => "DO"}
54
54
  %block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
55
55
  %value{:name => "ARG"}
56
- %block{:type => "hardware_smalrubot_v3_motor_speed"}
56
+ %block{:type => "hardware_smalrubot_v3_dc_motor_power_ratio"}
57
57
  %field{:name => "LOR"}<
58
58
  right
59
59
  %next
60
- %block{:type => "hardware_smalrubot_v3_motor_set_speed"}
60
+ %block{:type => "hardware_smalrubot_v3_dc_motor_set_power_ratio"}
61
61
  %field{:name => "LOR"}<
62
62
  left
63
63
  %value{:name => "SPEED"}
@@ -72,8 +72,8 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
72
72
  require "smalruby"
73
73
 
74
74
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
75
- p(car1.smalrubot_v3.right_motor.speed)
76
- car1.smalrubot_v3.left_motor.speed = 50
75
+ p(car1.smalrubot_v3.right_dc_motor_power_ratio)
76
+ car1.smalrubot_v3.left_dc_motor_power_ratio = 50
77
77
 
78
78
  """
79
79
 
@@ -88,11 +88,11 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
88
88
  %statement{:name => "DO"}
89
89
  %block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
90
90
  %value{:name => "ARG"}
91
- %block{:type => "hardware_smalrubot_v3_motor_speed"}
91
+ %block{:type => "hardware_smalrubot_v3_dc_motor_power_ratio"}
92
92
  %field{:name => "LOR"}<
93
93
  right
94
94
  %next
95
- %block{:type => "hardware_smalrubot_v3_motor_set_speed"}
95
+ %block{:type => "hardware_smalrubot_v3_dc_motor_set_power_ratio"}
96
96
  %field{:name => "LOR"}<
97
97
  left
98
98
  %value{:name => "SPEED"}
@@ -109,8 +109,8 @@ Feature: hardware_smalrubot_v3_motor_{speed,set_speed} block
109
109
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
110
110
 
111
111
  car1.on(:start) do
112
- p(smalrubot_v3.right_motor.speed)
113
- self.smalrubot_v3.left_motor.speed = 50
112
+ p(smalrubot_v3.right_dc_motor_power_ratio)
113
+ self.smalrubot_v3.left_dc_motor_power_ratio = 50
114
114
  end
115
115
 
116
116
  """
@@ -10,8 +10,8 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
10
10
  When 次のブロックを配置する:
11
11
  """
12
12
  %block{:type => "hardware_smalrubot_v3_led_turn_on_or_off", :x => "0", :y => "0"}
13
- %field{:name => "COLOUR"}<
14
- green
13
+ %field{:name => "LOR"}<
14
+ left
15
15
  %field{:name => "OOO"}<
16
16
  turn_off
17
17
  """
@@ -27,8 +27,8 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
27
27
  car1
28
28
  %statement{:name => "DO"}
29
29
  %block{:type => "hardware_smalrubot_v3_led_turn_on_or_off", :x => "0", :y => "0"}
30
- %field{:name => "COLOUR"}<
31
- green
30
+ %field{:name => "LOR"}<
31
+ left
32
32
  %field{:name => "OOO"}<
33
33
  turn_off
34
34
  """
@@ -39,7 +39,7 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
39
39
  require "smalruby"
40
40
 
41
41
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
42
- car1.smalrubot_v3.green_led.turn_off
42
+ car1.smalrubot_v3.turn_off_left_led
43
43
 
44
44
  """
45
45
 
@@ -53,8 +53,8 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
53
53
  %block{:type => "events_on_start"}
54
54
  %statement{:name => "DO"}
55
55
  %block{:type => "hardware_smalrubot_v3_led_turn_on_or_off", :x => "0", :y => "0"}
56
- %field{:name => "COLOUR"}<
57
- red
56
+ %field{:name => "LOR"}<
57
+ right
58
58
  %field{:name => "OOO"}<
59
59
  turn_on
60
60
  """
@@ -67,7 +67,7 @@ Feature: hardware_smalrubot_v3_led_turn_on_or_off block
67
67
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
68
68
 
69
69
  car1.on(:start) do
70
- smalrubot_v3.red_led.turn_on
70
+ smalrubot_v3.turn_on_right_led
71
71
  end
72
72
 
73
73
  """
@@ -1,13 +1,13 @@
1
1
  # encoding: utf-8
2
2
  # language: en
3
3
  @javascript
4
- Feature: hardware_smalrubot_s1_ir_photoreflector_value block
4
+ Feature: hardware_smalrubot_v3_sensor_value block
5
5
  Scenario: ブロックのみ配置する
6
6
  Given "ブロック" タブを表示する
7
7
 
8
8
  When 次のブロックを配置する:
9
9
  """
10
- %block{:type => "hardware_smalrubot_s1_ir_photoreflector_value", :x => "0", :y => "0"}
10
+ %block{:type => "hardware_smalrubot_v3_sensor_value", :x => "0", :y => "0"}
11
11
  %field{:name => "LOR"}<
12
12
  right
13
13
  """
@@ -22,7 +22,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
22
22
  """
23
23
  %block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
24
24
  %value{:name => "ARG"}
25
- %block{:type => "hardware_smalrubot_s1_ir_photoreflector_value", :x => "0", :y => "0"}
25
+ %block{:type => "hardware_smalrubot_v3_sensor_value", :x => "0", :y => "0"}
26
26
  %field{:name => "LOR"}<
27
27
  right
28
28
  """
@@ -50,7 +50,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
50
50
  %statement{:name => "DO"}
51
51
  %block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
52
52
  %value{:name => "ARG"}
53
- %block{:type => "hardware_smalrubot_s1_ir_photoreflector_value", :x => "0", :y => "0"}
53
+ %block{:type => "hardware_smalrubot_v3_sensor_value", :x => "0", :y => "0"}
54
54
  %field{:name => "LOR"}<
55
55
  right
56
56
  """
@@ -61,7 +61,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
61
61
  require "smalruby"
62
62
 
63
63
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
64
- p(car1.smalrubot_s1.right_ir_photoreflector_value)
64
+ p(car1.smalrubot_v3.right_sensor_value)
65
65
 
66
66
  """
67
67
 
@@ -81,7 +81,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
81
81
  %statement{:name => "DO"}
82
82
  %block{:type => "ruby_p", :x => "0", :y => "0", :inline => "true" }
83
83
  %value{:name => "ARG"}
84
- %block{:type => "hardware_smalrubot_s1_ir_photoreflector_value", :x => "0", :y => "0"}
84
+ %block{:type => "hardware_smalrubot_v3_sensor_value", :x => "0", :y => "0"}
85
85
  %field{:name => "LOR"}<
86
86
  left
87
87
  """
@@ -94,7 +94,7 @@ Feature: hardware_smalrubot_s1_ir_photoreflector_value block
94
94
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
95
95
 
96
96
  car1.on(:start) do
97
- p(smalrubot_s1.left_ir_photoreflector_value)
97
+ p(smalrubot_v3.left_sensor_value)
98
98
  end
99
99
 
100
100
  """
@@ -4,68 +4,70 @@ require_relative 'shared/block_examples'
4
4
 
5
5
  # rubocop:disable EmptyLines, LineLength
6
6
 
7
- describe RubyToBlock::Block, 'Smalrubot s1 blocks', to_blocks: true do
8
- parts = <<-EOS
7
+ describe RubyToBlock::Block, 'Smalrubot blocks', to_blocks: true do
8
+ %w(s1 v3).each do |smalrubot_version|
9
+ describe smalrubot_version do
10
+ parts = <<-EOS
9
11
  require "smalruby"
10
12
 
11
13
  init_hardware
12
14
  car1 = Character.new(costume: "car1.png", x: 0, y: 0, angle: 0)
13
15
 
14
16
  car1.on(:start) do
15
- smalrubot_s1.forward
16
- smalrubot_s1.backward
17
- smalrubot_s1.turn_left
18
- smalrubot_s1.turn_right
19
- smalrubot_s1.stop
17
+ smalrubot_#{smalrubot_version}.forward
18
+ smalrubot_#{smalrubot_version}.backward
19
+ smalrubot_#{smalrubot_version}.turn_left
20
+ smalrubot_#{smalrubot_version}.turn_right
21
+ smalrubot_#{smalrubot_version}.stop
20
22
 
21
- smalrubot_s1.forward(sec: 0.5)
22
- smalrubot_s1.backward(sec: 0.4)
23
- smalrubot_s1.turn_left(sec: 0.3)
24
- smalrubot_s1.turn_right(sec: 0.2)
25
- smalrubot_s1.stop(sec: 0.1)
23
+ smalrubot_#{smalrubot_version}.forward(sec: 0.5)
24
+ smalrubot_#{smalrubot_version}.backward(sec: 0.4)
25
+ smalrubot_#{smalrubot_version}.turn_left(sec: 0.3)
26
+ smalrubot_#{smalrubot_version}.turn_right(sec: 0.2)
27
+ smalrubot_#{smalrubot_version}.stop(sec: 0.1)
26
28
 
27
- p(smalrubot_s1.left_ir_photoreflector_value)
28
- p(smalrubot_s1.right_ir_photoreflector_value)
29
+ p(smalrubot_#{smalrubot_version}.left_sensor_value)
30
+ p(smalrubot_#{smalrubot_version}.right_sensor_value)
29
31
 
30
- smalrubot_s1.turn_on_white_led
31
- smalrubot_s1.turn_off_blue_led
32
+ smalrubot_#{smalrubot_version}.turn_on_left_led
33
+ smalrubot_#{smalrubot_version}.turn_off_right_led
32
34
 
33
- p(smalrubot_s1.left_dc_motor_power_ratio)
34
- p(smalrubot_s1.right_dc_motor_power_ratio)
35
+ p(smalrubot_#{smalrubot_version}.left_dc_motor_power_ratio)
36
+ p(smalrubot_#{smalrubot_version}.right_dc_motor_power_ratio)
35
37
 
36
- smalrubot_s1.left_dc_motor_power_ratio = 10
37
- smalrubot_s1.right_dc_motor_power_ratio = 90
38
+ smalrubot_#{smalrubot_version}.left_dc_motor_power_ratio = 10
39
+ smalrubot_#{smalrubot_version}.right_dc_motor_power_ratio = 90
38
40
  end
39
- car1.smalrubot_s1.forward
40
- car1.smalrubot_s1.backward
41
- car1.smalrubot_s1.turn_left
42
- car1.smalrubot_s1.turn_right
43
- car1.smalrubot_s1.stop
41
+ car1.smalrubot_#{smalrubot_version}.forward
42
+ car1.smalrubot_#{smalrubot_version}.backward
43
+ car1.smalrubot_#{smalrubot_version}.turn_left
44
+ car1.smalrubot_#{smalrubot_version}.turn_right
45
+ car1.smalrubot_#{smalrubot_version}.stop
44
46
 
45
- car1.smalrubot_s1.forward(sec: 0.5)
46
- car1.smalrubot_s1.backward(sec: 0.4)
47
- car1.smalrubot_s1.turn_left(sec: 0.3)
48
- car1.smalrubot_s1.turn_right(sec: 0.2)
49
- car1.smalrubot_s1.stop(sec: 0.1)
47
+ car1.smalrubot_#{smalrubot_version}.forward(sec: 0.5)
48
+ car1.smalrubot_#{smalrubot_version}.backward(sec: 0.4)
49
+ car1.smalrubot_#{smalrubot_version}.turn_left(sec: 0.3)
50
+ car1.smalrubot_#{smalrubot_version}.turn_right(sec: 0.2)
51
+ car1.smalrubot_#{smalrubot_version}.stop(sec: 0.1)
50
52
 
51
- p(car1.smalrubot_s1.left_ir_photoreflector_value)
52
- p(car1.smalrubot_s1.right_ir_photoreflector_value)
53
+ p(car1.smalrubot_#{smalrubot_version}.left_sensor_value)
54
+ p(car1.smalrubot_#{smalrubot_version}.right_sensor_value)
53
55
 
54
- car1.smalrubot_s1.turn_on_white_led
55
- car1.smalrubot_s1.turn_off_blue_led
56
+ car1.smalrubot_#{smalrubot_version}.turn_on_left_led
57
+ car1.smalrubot_#{smalrubot_version}.turn_off_right_led
56
58
 
57
- p(car1.smalrubot_s1.left_dc_motor_power_ratio)
58
- p(car1.smalrubot_s1.right_dc_motor_power_ratio)
59
+ p(car1.smalrubot_#{smalrubot_version}.left_dc_motor_power_ratio)
60
+ p(car1.smalrubot_#{smalrubot_version}.right_dc_motor_power_ratio)
59
61
 
60
- car1.smalrubot_s1.left_dc_motor_power_ratio = 10
61
- car1.smalrubot_s1.right_dc_motor_power_ratio = 90
62
- EOS
63
- describe compact_source_code(parts) do
64
- _parts = parts
65
- let(:data) { _parts }
62
+ car1.smalrubot_#{smalrubot_version}.left_dc_motor_power_ratio = 10
63
+ car1.smalrubot_#{smalrubot_version}.right_dc_motor_power_ratio = 90
64
+ EOS
65
+ describe compact_source_code(parts) do
66
+ _parts = parts
67
+ let(:data) { _parts }
66
68
 
67
- it '結果が正しいこと' do
68
- should eq_block_xml(<<-XML)
69
+ it '結果が正しいこと' do
70
+ should eq_block_xml(<<-XML)
69
71
  <character name="car1" x="0" y="0" angle="0" costumes="car1.png" />
70
72
  <block type="hardware_init_hardware" />
71
73
  <block type="character_new">
@@ -73,22 +75,22 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
73
75
  <statement name="DO">
74
76
  <block type="events_on_start">
75
77
  <statement name="DO">
76
- <block type="hardware_smalrubot_s1_action" inline="true">
78
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
77
79
  <field name="ACTION">forward</field>
78
80
  <next>
79
- <block type="hardware_smalrubot_s1_action" inline="true">
81
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
80
82
  <field name="ACTION">backward</field>
81
83
  <next>
82
- <block type="hardware_smalrubot_s1_action" inline="true">
84
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
83
85
  <field name="ACTION">turn_left</field>
84
86
  <next>
85
- <block type="hardware_smalrubot_s1_action" inline="true">
87
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
86
88
  <field name="ACTION">turn_right</field>
87
89
  <next>
88
- <block type="hardware_smalrubot_s1_action" inline="true">
90
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
89
91
  <field name="ACTION">stop</field>
90
92
  <next>
91
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
93
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
92
94
  <field name="ACTION">forward</field>
93
95
  <value name="SEC">
94
96
  <block type="math_number">
@@ -96,7 +98,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
96
98
  </block>
97
99
  </value>
98
100
  <next>
99
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
101
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
100
102
  <field name="ACTION">backward</field>
101
103
  <value name="SEC">
102
104
  <block type="math_number">
@@ -104,7 +106,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
104
106
  </block>
105
107
  </value>
106
108
  <next>
107
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
109
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
108
110
  <field name="ACTION">turn_left</field>
109
111
  <value name="SEC">
110
112
  <block type="math_number">
@@ -112,7 +114,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
112
114
  </block>
113
115
  </value>
114
116
  <next>
115
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
117
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
116
118
  <field name="ACTION">turn_right</field>
117
119
  <value name="SEC">
118
120
  <block type="math_number">
@@ -120,7 +122,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
120
122
  </block>
121
123
  </value>
122
124
  <next>
123
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
125
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
124
126
  <field name="ACTION">stop</field>
125
127
  <value name="SEC">
126
128
  <block type="math_number">
@@ -130,41 +132,41 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
130
132
  <next>
131
133
  <block type="ruby_p" inline="true">
132
134
  <value name="ARG">
133
- <block type="hardware_smalrubot_s1_ir_photoreflector_value">
135
+ <block type="hardware_smalrubot_#{smalrubot_version}_sensor_value">
134
136
  <field name="LOR">left</field>
135
137
  </block>
136
138
  </value>
137
139
  <next>
138
140
  <block type="ruby_p" inline="true">
139
141
  <value name="ARG">
140
- <block type="hardware_smalrubot_s1_ir_photoreflector_value">
142
+ <block type="hardware_smalrubot_#{smalrubot_version}_sensor_value">
141
143
  <field name="LOR">right</field>
142
144
  </block>
143
145
  </value>
144
146
  <next>
145
- <block type="hardware_smalrubot_s1_led_turn_on_or_off" inline="true">
146
- <field name="COLOUR">white</field>
147
+ <block type="hardware_smalrubot_#{smalrubot_version}_led_turn_on_or_off" inline="true">
148
+ <field name="LOR">left</field>
147
149
  <field name="OOO">turn_on</field>
148
150
  <next>
149
- <block type="hardware_smalrubot_s1_led_turn_on_or_off" inline="true">
150
- <field name="COLOUR">blue</field>
151
+ <block type="hardware_smalrubot_#{smalrubot_version}_led_turn_on_or_off" inline="true">
152
+ <field name="LOR">right</field>
151
153
  <field name="OOO">turn_off</field>
152
154
  <next>
153
155
  <block type="ruby_p" inline="true">
154
156
  <value name="ARG">
155
- <block type="hardware_smalrubot_s1_dc_motor_power_ratio">
157
+ <block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_power_ratio">
156
158
  <field name="LOR">left</field>
157
159
  </block>
158
160
  </value>
159
161
  <next>
160
162
  <block type="ruby_p" inline="true">
161
163
  <value name="ARG">
162
- <block type="hardware_smalrubot_s1_dc_motor_power_ratio">
164
+ <block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_power_ratio">
163
165
  <field name="LOR">right</field>
164
166
  </block>
165
167
  </value>
166
168
  <next>
167
- <block type="hardware_smalrubot_s1_dc_motor_set_power_ratio" inline="true">
169
+ <block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_set_power_ratio" inline="true">
168
170
  <field name="LOR">left</field>
169
171
  <value name="SPEED">
170
172
  <block type="math_number">
@@ -172,7 +174,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
172
174
  </block>
173
175
  </value>
174
176
  <next>
175
- <block type="hardware_smalrubot_s1_dc_motor_set_power_ratio" inline="true">
177
+ <block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_set_power_ratio" inline="true">
176
178
  <field name="LOR">right</field>
177
179
  <value name="SPEED">
178
180
  <block type="math_number">
@@ -216,22 +218,22 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
216
218
  </block>
217
219
  </statement>
218
220
  <next>
219
- <block type="hardware_smalrubot_s1_action" inline="true">
221
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
220
222
  <field name="ACTION">forward</field>
221
223
  <next>
222
- <block type="hardware_smalrubot_s1_action" inline="true">
224
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
223
225
  <field name="ACTION">backward</field>
224
226
  <next>
225
- <block type="hardware_smalrubot_s1_action" inline="true">
227
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
226
228
  <field name="ACTION">turn_left</field>
227
229
  <next>
228
- <block type="hardware_smalrubot_s1_action" inline="true">
230
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
229
231
  <field name="ACTION">turn_right</field>
230
232
  <next>
231
- <block type="hardware_smalrubot_s1_action" inline="true">
233
+ <block type="hardware_smalrubot_#{smalrubot_version}_action" inline="true">
232
234
  <field name="ACTION">stop</field>
233
235
  <next>
234
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
236
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
235
237
  <field name="ACTION">forward</field>
236
238
  <value name="SEC">
237
239
  <block type="math_number">
@@ -239,7 +241,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
239
241
  </block>
240
242
  </value>
241
243
  <next>
242
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
244
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
243
245
  <field name="ACTION">backward</field>
244
246
  <value name="SEC">
245
247
  <block type="math_number">
@@ -247,7 +249,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
247
249
  </block>
248
250
  </value>
249
251
  <next>
250
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
252
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
251
253
  <field name="ACTION">turn_left</field>
252
254
  <value name="SEC">
253
255
  <block type="math_number">
@@ -255,7 +257,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
255
257
  </block>
256
258
  </value>
257
259
  <next>
258
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
260
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
259
261
  <field name="ACTION">turn_right</field>
260
262
  <value name="SEC">
261
263
  <block type="math_number">
@@ -263,7 +265,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
263
265
  </block>
264
266
  </value>
265
267
  <next>
266
- <block type="hardware_smalrubot_s1_action_with_sec" inline="true">
268
+ <block type="hardware_smalrubot_#{smalrubot_version}_action_with_sec" inline="true">
267
269
  <field name="ACTION">stop</field>
268
270
  <value name="SEC">
269
271
  <block type="math_number">
@@ -273,41 +275,41 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
273
275
  <next>
274
276
  <block type="ruby_p" inline="true">
275
277
  <value name="ARG">
276
- <block type="hardware_smalrubot_s1_ir_photoreflector_value">
278
+ <block type="hardware_smalrubot_#{smalrubot_version}_sensor_value">
277
279
  <field name="LOR">left</field>
278
280
  </block>
279
281
  </value>
280
282
  <next>
281
283
  <block type="ruby_p" inline="true">
282
284
  <value name="ARG">
283
- <block type="hardware_smalrubot_s1_ir_photoreflector_value">
285
+ <block type="hardware_smalrubot_#{smalrubot_version}_sensor_value">
284
286
  <field name="LOR">right</field>
285
287
  </block>
286
288
  </value>
287
289
  <next>
288
- <block type="hardware_smalrubot_s1_led_turn_on_or_off" inline="true">
289
- <field name="COLOUR">white</field>
290
+ <block type="hardware_smalrubot_#{smalrubot_version}_led_turn_on_or_off" inline="true">
291
+ <field name="LOR">left</field>
290
292
  <field name="OOO">turn_on</field>
291
293
  <next>
292
- <block type="hardware_smalrubot_s1_led_turn_on_or_off" inline="true">
293
- <field name="COLOUR">blue</field>
294
+ <block type="hardware_smalrubot_#{smalrubot_version}_led_turn_on_or_off" inline="true">
295
+ <field name="LOR">right</field>
294
296
  <field name="OOO">turn_off</field>
295
297
  <next>
296
298
  <block type="ruby_p" inline="true">
297
299
  <value name="ARG">
298
- <block type="hardware_smalrubot_s1_dc_motor_power_ratio">
300
+ <block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_power_ratio">
299
301
  <field name="LOR">left</field>
300
302
  </block>
301
303
  </value>
302
304
  <next>
303
305
  <block type="ruby_p" inline="true">
304
306
  <value name="ARG">
305
- <block type="hardware_smalrubot_s1_dc_motor_power_ratio">
307
+ <block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_power_ratio">
306
308
  <field name="LOR">right</field>
307
309
  </block>
308
310
  </value>
309
311
  <next>
310
- <block type="hardware_smalrubot_s1_dc_motor_set_power_ratio" inline="true">
312
+ <block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_set_power_ratio" inline="true">
311
313
  <field name="LOR">left</field>
312
314
  <value name="SPEED">
313
315
  <block type="math_number">
@@ -315,7 +317,7 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
315
317
  </block>
316
318
  </value>
317
319
  <next>
318
- <block type="hardware_smalrubot_s1_dc_motor_set_power_ratio" inline="true">
320
+ <block type="hardware_smalrubot_#{smalrubot_version}_dc_motor_set_power_ratio" inline="true">
319
321
  <field name="LOR">right</field>
320
322
  <value name="SPEED">
321
323
  <block type="math_number">
@@ -362,6 +364,8 @@ car1.smalrubot_s1.right_dc_motor_power_ratio = 90
362
364
  </statement>
363
365
  </block>
364
366
  XML
367
+ end
368
+ end
365
369
  end
366
370
  end
367
371
  end