Class: BinData::DSLMixin::ChoiceBlockParser

Inherits:
Object
  • Object
show all
Defined in:
lib/bindata/dsl.rb

Class Method Summary collapse

Class Method Details

.all_blank?(array) ⇒ Boolean

Returns:

  • (Boolean)


321
322
323
# File 'lib/bindata/dsl.rb', line 321

def self.all_blank?(array)
  array.all? { |el| el == "" }
end

.extract_params(endian, &block) ⇒ Object



307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/bindata/dsl.rb', line 307

def self.extract_params(endian, &block)
  parser = DSLParser.new(BinData::Choice, :multiple_fields, :all_or_none_fieldnames)
  parser.endian endian
  parser.instance_eval(&block)

  if all_blank?(parser.fields.field_names)
    {:choices => parser.fields.collect { |f| f.to_type_params }}
  else
    choices = {}
    parser.fields.each { |f| choices[f.name] = f.to_type_params }
    {:choices => choices}
  end
end