Class: SexpVariableBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/quby/compiler/dsl/sexp_variable_builder.rb

Overview

sexp_variable :myvar do

sum(number_values(:v_1, :v_2))

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, type:, &block) ⇒ SexpVariableBuilder

Returns a new instance of SexpVariableBuilder.



12
13
14
15
16
# File 'lib/quby/compiler/dsl/sexp_variable_builder.rb', line 12

def initialize(key, type:, &block)
  @key = key
  @type = type
  @calculation = instance_eval(&block)
end

Instance Attribute Details

#calculationObject (readonly)

Returns the value of attribute calculation.



10
11
12
# File 'lib/quby/compiler/dsl/sexp_variable_builder.rb', line 10

def calculation
  @calculation
end

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'lib/quby/compiler/dsl/sexp_variable_builder.rb', line 10

def key
  @key
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/quby/compiler/dsl/sexp_variable_builder.rb', line 10

def type
  @type
end

Instance Method Details

#buildObject



52
53
54
# File 'lib/quby/compiler/dsl/sexp_variable_builder.rb', line 52

def build
  Entities::SexpVariable.new(key:, calculation:, type:)
end

#number_value(key) ⇒ Object



22
23
24
# File 'lib/quby/compiler/dsl/sexp_variable_builder.rb', line 22

def number_value(key)
  Entities::SexpVariables::NumberValue.new(op: :number_value, key: key)
end

#number_values(*keys) ⇒ Object



26
27
28
# File 'lib/quby/compiler/dsl/sexp_variable_builder.rb', line 26

def number_values(*keys)
  keys.map { |key| number_value(key) }
end

#round(value) ⇒ Object



48
49
50
# File 'lib/quby/compiler/dsl/sexp_variable_builder.rb', line 48

def round(value)
  Entities::SexpVariables::NumberMethod.new(op: :round, value: value)
end

#string_value(key) ⇒ Object



18
19
20
# File 'lib/quby/compiler/dsl/sexp_variable_builder.rb', line 18

def string_value(key)
  Entities::SexpVariables::StringValue.new(op: :string_value, key: key)
end