Module: Vindetta::Decoder::DSL

Included in:
Result
Defined in:
lib/vindetta/decoder/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(mod) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/vindetta/decoder/dsl.rb', line 22

def self.extended(mod)
  mod.instance_eval do
    define_method :value_for do |variable_id|
      result = @variables.find { |r| r["VariableId"] == variable_id }
      return unless result

      result["Value"]
    end
  end
end

Instance Method Details

#decoded_attributesObject



4
5
6
# File 'lib/vindetta/decoder/dsl.rb', line 4

def decoded_attributes
  @decoded_attributes ||= []
end

#has_value(name, variable_id, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vindetta/decoder/dsl.rb', line 8

def has_value(name, variable_id, options = {})
  decoded_attributes << name

  define_method name do
    value = value_for(variable_id)

    case options[:type]
    when :int then value&.to_i
    else
      value
    end
  end
end