class Ecoportal::API::V2::Page::Components

Public Instance Methods

add(label:, type:) { |fld| ... } click to toggle source
# File lib/ecoportal/api/v2/page/components.rb, line 30
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
get_by_name(name, type: nil) click to toggle source
# File lib/ecoportal/api/v2/page/components.rb, line 22
def get_by_name(name, type: nil)
  pool = type ? get_by_type(type) : self

  pool.select do |comp|
    comp.label.to_s.strip.downcase == name.to_s.strip.downcase
  end.first
end
get_by_type(type) click to toggle source
# File lib/ecoportal/api/v2/page/components.rb, line 16
def get_by_type(type)
  self.select do |comp|
    comp.type.downcase == type.to_s.strip.downcase
  end
end