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.



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

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

Instance Method Details

#[](idx) ⇒ Object



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

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

#add_field(type, name, params) ⇒ Object



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

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)


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

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

#any_field_has_parameter?(parameter) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/bindata/sanitize.rb', line 126

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

#each(&block) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @fields.empty?
end

#field_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#field_namesObject



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

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

#lengthObject



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

def length
  @fields.length
end

#no_field_names_blank?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/bindata/sanitize.rb', line 122

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

#raw_fieldsObject



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

def raw_fields
  @fields.dup
end