Class: SexpVariableBuilder
- Inherits:
-
Object
- Object
- SexpVariableBuilder
- 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
-
#calculation ⇒ Object
readonly
Returns the value of attribute calculation.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(key, type:, &block) ⇒ SexpVariableBuilder
constructor
A new instance of SexpVariableBuilder.
- #number_value(key) ⇒ Object
- #number_values(*keys) ⇒ Object
- #round(value) ⇒ Object
- #string_value(key) ⇒ Object
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
#calculation ⇒ Object (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 |
#key ⇒ Object (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 |
#type ⇒ Object (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
#build ⇒ Object
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 |