class Presenting::FieldSet
Public Class Methods
new(field_class, primary, secondary)
click to toggle source
# File lib/presenting/field_set.rb, line 2 def initialize(field_class, primary, secondary) @klass = field_class @primary_attribute = primary @secondary_attribute = secondary end
Public Instance Methods
<<(field)
click to toggle source
Calls superclass method
# File lib/presenting/field_set.rb, line 8 def <<(field) if field.is_a? Hash k, v = *field.to_a.first opts = v.is_a?(Hash) ? v : {@secondary_attribute => v} opts[@primary_attribute] = k else opts = {@primary_attribute => field} end super @klass.new(opts) end
[](key)
click to toggle source
# File lib/presenting/field_set.rb, line 19 def [](key) detect{|i| i.send(@primary_attribute) == key} end
[]=(key, val)
click to toggle source
# File lib/presenting/field_set.rb, line 23 def []=(key, val) self << {key => val} end