Class: RuboCop::Isucon::GDA::WhereCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/isucon/gda/where_condition.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator: nil, operands: []) ⇒ WhereCondition

Returns a new instance of WhereCondition.

Parameters:



18
19
20
21
# File 'lib/rubocop/isucon/gda/where_condition.rb', line 18

def initialize(operator: nil, operands: [])
  @operator = operator
  @operands = operands
end

Instance Attribute Details

#operandsArray<RuboCop::Isucon::GDA::WhereOperand>



14
15
16
# File 'lib/rubocop/isucon/gda/where_condition.rb', line 14

def operands
  @operands
end

#operatorString

Returns:

  • (String)


10
11
12
# File 'lib/rubocop/isucon/gda/where_condition.rb', line 10

def operator
  @operator
end

Instance Method Details

#column_operandString?

Returns:

  • (String, nil)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubocop/isucon/gda/where_condition.rb', line 24

def column_operand
  operand0_value = operands[0].value

  return operand0_value if operands.count == 1

  operand1_value = operands[1].value

  operand0_type = operand_type(operand0_value)
  operand1_type = operand_type(operand1_value)

  return operand0_value if operand0_type == :column || operand1_type == :value
  return operand1_value if operand1_type == :column || operand0_type == :value

  nil
end

#value_operandString?

Returns:

  • (String, nil)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubocop/isucon/gda/where_condition.rb', line 41

def value_operand
  return nil if operands.count == 1

  operand0_value = operands[0].value
  operand1_value = operands[1].value

  operand0_type = operand_type(operand0_value)
  operand1_type = operand_type(operand1_value)

  return operand0_value if operand0_type == :value || operand1_type == :column
  return operand1_value if operand1_type == :value || operand0_type == :column

  nil
end