Class: ConceptQL::Converter::Operator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, *values) ⇒ Operator

Returns a new instance of Operator.



14
15
16
17
18
# File 'lib/conceptql/converter.rb', line 14

def initialize(type, *values)
  @type, @values = type, values.flatten
  @options = @values.extract_options!.deep_rekey
  @values = @values
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/conceptql/converter.rb', line 13

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/conceptql/converter.rb', line 13

def type
  @type
end

#valuesObject (readonly)

Returns the value of attribute values.



13
14
15
# File 'lib/conceptql/converter.rb', line 13

def values
  @values
end

Instance Method Details

#argsObject



20
21
22
# File 'lib/conceptql/converter.rb', line 20

def args
  values.select { |s| !s.is_a?(Operator) }
end

#converted_optionsObject



28
29
30
31
32
33
34
35
36
# File 'lib/conceptql/converter.rb', line 28

def converted_options
  options.update_values do |value|
    if value.is_a?(Operator)
      value.to_list_syntax
    else
      value
    end
  end
end

#to_list_syntaxObject



38
39
40
41
42
43
44
# File 'lib/conceptql/converter.rb', line 38

def to_list_syntax
  stmt = [type]
  stmt += args unless args.empty?
  stmt += upstreams.map(&:to_list_syntax) unless upstreams.empty?
  stmt << converted_options unless options.empty?
  stmt
end

#upstreamsObject



24
25
26
# File 'lib/conceptql/converter.rb', line 24

def upstreams
  values.select { |s| s.is_a?(Operator) }
end