Class: Conformity::Fields
- Inherits:
-
Object
- Object
- Conformity::Fields
- Defined in:
- lib/conformity/fields.rb
Instance Method Summary collapse
- #add_field(field) ⇒ Object
- #add_new_field(name, opts = {}) ⇒ Object
- #field_names ⇒ Object
- #fields ⇒ Object
- #find(name) ⇒ Object
- #set(name, value) ⇒ Object
- #set_all(hash) ⇒ Object
- #value(name) ⇒ Object
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_names ⇒ Object
15 16 17 |
# File 'lib/conformity/fields.rb', line 15 def field_names fields.map { |field| field.name } end |
#fields ⇒ Object
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 |