NYULibraries/gather_content-api

View on GitHub
lib/gather_content/config/elements/section.rb

Summary

Maintainability
A
0 mins
Test Coverage
module GatherContent
  module Config
    module Element
      class Section
        attr_accessor :name, :title, :subtitle

        def initialize(name = "", title = "", subtitle = "")
          @name = name
          @title = title
          @subtitle = subtitle
        end

        def serialize(options = nil)
          raise ArgumentError, "name is required" unless name.present?
          raise ArgumentError, "title is required" unless title.present?

          {
            type: "section",
            name: name,
            title: title,
            subtitle: subtitle
          }
        end

        def to_json(options = nil)
          serialize.to_json(options)
        end
      end
    end
  end
end