lib/ecoportal/api/v2/page/components.rb in ecoportal-api-v2-0.8.13 vs lib/ecoportal/api/v2/page/components.rb in ecoportal-api-v2-0.8.14
- old
+ new
@@ -11,36 +11,60 @@
end
end
order_matters = true
+ def ooze
+ self._parent.ooze
+ end
+
+ # @return [Ecoportal::API::V2::Page::Component] the field with `id`
def get_by_id(id)
self.find do |comp|
comp.id == id
end
end
+ # @return [Array<Ecoportal::API::V2::Page::Component>] the fields of that `type`
def get_by_type(type)
self.select do |comp|
comp.type.downcase == type.to_s.strip.downcase
end
end
+ # @param name [String, Regexp] the `name` to search the field based on their `label`
+ # @param type [String] the `type` of the fields to be included
+ # @return [Array<Ecoportal::API::V2::Page::Component>] the fields that match `name`.
def get_by_name(name, type: nil)
pool = type ? get_by_type(type) : self
pool.select do |comp|
same_string?(comp.label, name)
end
end
+ # It creates a **new** component
+ # @param label [String, nil]
+ # @param type [String] the type of the field
+ # @yield [field] do some stuff with field
+ # @yieldparam [Ecoportal::API::V2::Page::Component] the created field
+ # @return [Ecoportal::API::V2::Page::Component] the created field.
def add(label:, type:)
fld_doc = component_class.new_doc(type: type)
upsert!(fld_doc) do |fld|
fld.label = label
yield(fld) if block_given?
end
end
+ # @return [Array<Ecoportal::API::V2::Page::Component>] **orphaned** fields (with no section).
+ def unattached
+ select {|comp| !comp.attached?}
+ end
+
+ # @return [Array<Ecoportal::API::V2::Page::Component>] fields belonging to more than one section.
+ def multi_section
+ select {|comp| comp.multi_section?}
+ end
end
end
end
end
end