Parent

Files

Class/Module Index [+]

Quicksearch

BinData::DSLMixin::DSLFieldParser

Extracts the details from a field declaration.

Attributes

name[R]
params[R]
type[R]

Public Class Methods

new(endian, symbol, *args, &block) click to toggle source
# File lib/bindata/dsl.rb, line 313
def initialize(endian, symbol, *args, &block)
  @endian = endian
  @type   = symbol
  @name   = name_from_field_declaration(args)
  @params = params_from_field_declaration(args, &block)
end

Public Instance Methods

name_from_field_declaration(args) click to toggle source
# File lib/bindata/dsl.rb, line 322
def name_from_field_declaration(args)
  name, params = args
  if name == "" or name.is_a?(Hash)
    nil
  else
    name
  end
end
params_from_args(args) click to toggle source
# File lib/bindata/dsl.rb, line 341
def params_from_args(args)
  name, params = args
  params = name if name.is_a?(Hash)

  params || {}
end
params_from_block(&block) click to toggle source
# File lib/bindata/dsl.rb, line 348
def params_from_block(&block)
  bindata_classes = {
    :array  => BinData::Array,
    :buffer => BinData::Buffer,
    :choice => BinData::Choice,
    :struct => BinData::Struct
  }

  if bindata_classes.include?(@type)
    parser = DSLParser.new(bindata_classes[@type], @type)
    parser.endian(@endian)
    parser.instance_eval(&block)

    parser.dsl_params
  else
    {}
  end
end
params_from_field_declaration(args, &block) click to toggle source
# File lib/bindata/dsl.rb, line 331
def params_from_field_declaration(args, &block)
  params = params_from_args(args)

  if block_given?
    params.merge(params_from_block(&block))
  else
    params
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.