diff --git a/lib/govuk_design_system_formbuilder.rb b/lib/govuk_design_system_formbuilder.rb index 31062e8a..9c305c09 100644 --- a/lib/govuk_design_system_formbuilder.rb +++ b/lib/govuk_design_system_formbuilder.rb @@ -2,6 +2,8 @@ require 'govuk_design_system_formbuilder/builder' require 'govuk_design_system_formbuilder/base' +require 'govuk_design_system_formbuilder/traits/collection_item' + require 'govuk_design_system_formbuilder/elements/hint' require 'govuk_design_system_formbuilder/elements/label' require 'govuk_design_system_formbuilder/elements/date' diff --git a/lib/govuk_design_system_formbuilder/traits/collection_item.rb b/lib/govuk_design_system_formbuilder/traits/collection_item.rb new file mode 100644 index 00000000..9dacd5b5 --- /dev/null +++ b/lib/govuk_design_system_formbuilder/traits/collection_item.rb @@ -0,0 +1,18 @@ +module GOVUKDesignSystemFormBuilder + module Elements + module Traits + module CollectionItem + private + + def retrieve(item, text_method) + case text_method + when Symbol, String + item.send(text_method) + when Proc + text_method.call(item) + end + end + end + end + end +end