Class: BlocklyInterpreter::DSL::BinaryOperationDSLGenerator
  
  
  
  Instance Attribute Summary collapse
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #deep_flatten, #formatted_keyword_args, #indent, #keyword_args_without_defaults, #method_call, #method_call_with_block_or_nothing, #method_call_with_possible_block, #start_block_to_dsl, #strip_trailing_whitespace, #timestamp_to_dsl
  Constructor Details
  
    
  
  
    
Returns a new instance of BinaryOperationDSLGenerator.
   
 
  
  
    | 
223
224
225
226 | # File 'lib/blockly_interpreter/dsl.rb', line 223
def initialize(block, dsl_method_name)
  @block = block
  @dsl_method_name = dsl_method_name
end | 
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #block  ⇒ Object  
  
  
  
  
    
Returns the value of attribute block.
   
 
  
  
    | 
221
222
223 | # File 'lib/blockly_interpreter/dsl.rb', line 221
def block
  @block
end | 
 
    
      
      
      
  
  
    #dsl_method_name  ⇒ Object  
  
  
  
  
    
Returns the value of attribute dsl_method_name.
   
 
  
  
    | 
221
222
223 | # File 'lib/blockly_interpreter/dsl.rb', line 221
def dsl_method_name
  @dsl_method_name
end | 
 
    
   
  
    Instance Method Details
    
      
  
  
    #block_contents  ⇒ Object 
  
  
  
  
    | 
248
249
250
251
252
253
254 | # File 'lib/blockly_interpreter/dsl.rb', line 248
def block_contents
  cast_a, cast_b = cast_operands
  [
    value_block('A', cast_a),
    value_block('B', cast_b)
  ].compact
end | 
 
    
      
  
  
    #cast_operands  ⇒ Object 
  
  
  
  
    | 
236
237
238
239
240
241 | # File 'lib/blockly_interpreter/dsl.rb', line 236
def cast_operands
  @cast_operands ||= begin
    a, b = ['A', 'B'].map { |value_name| block.values[value_name] }
    [a, b].map { |value| castable_static_value value }
  end
end | 
 
    
      
  
  
    #castable_static_value(value)  ⇒ Object 
  
  
  
 
    
      
  
  
    #dsl  ⇒ Object 
  
  
  
  
    | 
266
267
268 | # File 'lib/blockly_interpreter/dsl.rb', line 266
def dsl
  method_call_with_possible_block(dsl_method_name, method_args.join(', '), block_contents)
end | 
 
    
      
  
  
    #method_args  ⇒ Object 
  
  
  
  
    | 
256
257
258
259
260
261
262
263
264 | # File 'lib/blockly_interpreter/dsl.rb', line 256
def method_args
  args = [block.fields['OP'].to_sym.inspect]
  cast_a, cast_b = cast_operands
  args << cast_a.inspect if cast_a || cast_b
  args << cast_b.inspect if cast_b
  args
end | 
 
    
      
  
  
    #value_block(value_name, cast_operand)  ⇒ Object 
  
  
  
  
    | 
243
244
245
246 | # File 'lib/blockly_interpreter/dsl.rb', line 243
def value_block(value_name, cast_operand)
  return if cast_operand
  method_call_with_block_or_nothing(value_name.downcase, '', block.values[value_name])
end |