Class: BinData::SanitizedFields

Inherits:
SanitizedParameter show all
Defined in:
lib/bindata/sanitize.rb

Overview


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sanitizer) ⇒ SanitizedFields

Returns a new instance of SanitizedFields.



238
239
240
241
242
# File 'lib/bindata/sanitize.rb', line 238

def initialize(sanitizer)
  @sanitizer = sanitizer
  @fields = []
  @field_names = nil
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



243
244
245
# File 'lib/bindata/sanitize.rb', line 243

def fields
  @fields
end

Instance Method Details

#[](idx) ⇒ Object



250
251
252
# File 'lib/bindata/sanitize.rb', line 250

def [](idx)
  @fields[idx]
end

#add_field(type, name, params, endian) ⇒ Object



245
246
247
248
# File 'lib/bindata/sanitize.rb', line 245

def add_field(type, name, params, endian)
  @field_names = nil
  @fields << SanitizedField.new(@sanitizer, name, type, params, endian)
end

#copy_fields(other) ⇒ Object



263
264
265
266
# File 'lib/bindata/sanitize.rb', line 263

def copy_fields(other)
  @field_names = nil
  @fields.concat(other.fields)
end

#empty?Boolean

Returns:

  • (Boolean)


254
255
256
# File 'lib/bindata/sanitize.rb', line 254

def empty?
  @fields.empty?
end

#field_namesObject



258
259
260
261
# File 'lib/bindata/sanitize.rb', line 258

def field_names
  # memoize field names to reduce duplicate copies
  @field_names ||= @fields.collect { |field| field.name }
end