Class: Conformity::Fields

Inherits:
Object
  • Object
show all
Defined in:
lib/conformity/fields.rb

Instance Method Summary collapse

Instance Method Details

#add_field(field) ⇒ Object



7
8
9
# File 'lib/conformity/fields.rb', line 7

def add_field(field)
  fields << field
end

#add_new_field(name, opts = {}) ⇒ Object



11
12
13
# File 'lib/conformity/fields.rb', line 11

def add_new_field(name, opts={})
  add_field(Field.new(name, opts))
end

#field_namesObject



15
16
17
# File 'lib/conformity/fields.rb', line 15

def field_names
  fields.map { |field| field.name }
end

#fieldsObject



3
4
5
# File 'lib/conformity/fields.rb', line 3

def fields
  @fields ||= []
end

#find(name) ⇒ Object



19
20
21
# File 'lib/conformity/fields.rb', line 19

def find(name)
  fields.select { |field| field.name == name }.first
end

#set(name, value) ⇒ Object



27
28
29
# File 'lib/conformity/fields.rb', line 27

def set(name, value)
  find(name).value = value
end

#set_all(hash) ⇒ Object



31
32
33
# File 'lib/conformity/fields.rb', line 31

def set_all(hash)
  hash.each { |name, value| set(name, value) unless find(name).nil? }
end

#value(name) ⇒ Object



23
24
25
# File 'lib/conformity/fields.rb', line 23

def value(name)
  find(name).value
end