Class: BinData::SanitizedFields

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

Overview


Instance Method Summary collapse

Constructor Details

#initialize(hints, base_fields = nil) ⇒ SanitizedFields

Returns a new instance of SanitizedFields.



71
72
73
74
# File 'lib/bindata/sanitize.rb', line 71

def initialize(hints, base_fields = nil)
  @hints = hints
  @fields =  base_fields ? base_fields.raw_fields : []
end

Instance Method Details

#[](idx) ⇒ Object



86
87
88
# File 'lib/bindata/sanitize.rb', line 86

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

#add_field(type, name, params) ⇒ Object



76
77
78
79
80
# File 'lib/bindata/sanitize.rb', line 76

def add_field(type, name, params)
  name = nil if name == ""

  @fields << SanitizedField.new(name, type, params, @hints)
end

#all_field_names_blank?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/bindata/sanitize.rb', line 110

def all_field_names_blank?
  @fields.all? { |f| f.name.nil? }
end

#any_field_has_parameter?(parameter) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/bindata/sanitize.rb', line 118

def any_field_has_parameter?(parameter)
  @fields.any? { |f| f.has_parameter?(parameter) }
end

#each(&block) ⇒ Object



98
99
100
# File 'lib/bindata/sanitize.rb', line 98

def each(&block)
  @fields.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/bindata/sanitize.rb', line 90

def empty?
  @fields.empty?
end

#field_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/bindata/sanitize.rb', line 106

def field_name?(name)
  @fields.detect { |f| f.name_as_sym == name.to_sym }
end

#field_namesObject



102
103
104
# File 'lib/bindata/sanitize.rb', line 102

def field_names
  @fields.collect(&:name_as_sym)
end

#lengthObject



94
95
96
# File 'lib/bindata/sanitize.rb', line 94

def length
  @fields.length
end

#no_field_names_blank?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/bindata/sanitize.rb', line 114

def no_field_names_blank?
  @fields.all? { |f| f.name != nil }
end

#raw_fieldsObject



82
83
84
# File 'lib/bindata/sanitize.rb', line 82

def raw_fields
  @fields.dup
end