Class: FormObj::Struct::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/form_obj/struct/attributes.rb

Direct Known Subclasses

Form::Attributes

Instance Method Summary collapse

Constructor Details

#initialize(items = []) ⇒ Attributes

Returns a new instance of Attributes.



4
5
6
# File 'lib/form_obj/struct/attributes.rb', line 4

def initialize(items = [])
  @items = items
end

Instance Method Details

#add(attribute) ⇒ Object



8
9
10
11
12
13
14
# 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

#map(*args, &block) ⇒ Object



16
17
18
# File 'lib/form_obj/struct/attributes.rb', line 16

def map(*args, &block)
  @items.map(*args, &block)
end