Sha256: 8450ada18518d6103758cf86e5ca60c455ba22f3fabafe51e00920a98aefdab3

Contents?: true

Size: 722 Bytes

Versions: 11

Compression:

Stored size: 722 Bytes

Contents

module Vindetta
  class Decoder
    module DSL
      def decoded_attributes
        @decoded_attributes ||= []
      end

      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

      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
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vindetta-0.19.0 lib/vindetta/decoder/dsl.rb
vindetta-0.17.1 lib/vindetta/decoder/dsl.rb
vindetta-0.17.0 lib/vindetta/decoder/dsl.rb
vindetta-0.16.0 lib/vindetta/decoder/dsl.rb
vindetta-0.15.0 lib/vindetta/decoder/dsl.rb
vindetta-0.14.0 lib/vindetta/decoder/dsl.rb
vindetta-0.13.0 lib/vindetta/decoder/dsl.rb
vindetta-0.12.0 lib/vindetta/decoder/dsl.rb
vindetta-0.11.0 lib/vindetta/decoder/dsl.rb
vindetta-0.10.0 lib/vindetta/decoder/dsl.rb
vindetta-0.9.0 lib/vindetta/decoder/dsl.rb