class FormObj::Struct::Attributes

Public Class Methods

new(items = []) click to toggle source
# File lib/form_obj/struct/attributes.rb, line 4
def initialize(items = [])
  @items = items
end

Public Instance Methods

add(attribute) click to toggle source
# File lib/form_obj/struct/attributes.rb, line 8
def add(attribute)
  if @items.map(&:name).include? attribute.name
    self.class.new(@items.map { |item| item.name == attribute.name ? attribute : item })
  else
    self.class.new(@items + [attribute])
  end
end
each(&block) click to toggle source
# File lib/form_obj/struct/attributes.rb, line 16
def each(&block)
  @items.each(&block)
end
find(name) click to toggle source
# File lib/form_obj/struct/attributes.rb, line 20
def find(name)
  @items.find { |item| item.name == name.to_sym }
end
map(*args, &block) click to toggle source
# File lib/form_obj/struct/attributes.rb, line 24
def map(*args, &block)
  @items.map(*args, &block)
end
reduce(*args, &block) click to toggle source
# File lib/form_obj/struct/attributes.rb, line 28
def reduce(*args, &block)
  @items.reduce(*args, &block)
end