<commit_before>require 'formular/elements/module'
require 'formular/elements/modules/collection'
require 'formular/elements/modules/labels'

module Formular
  module Elements
    module Modules
      # this module is used to correctly set the :checked attribute
      # based on the reader value.
      # It also provides an API to assist in generating checkable html (e.g. checkable labels)
      # and create collections of checkable controls from an enumerable variable.
      module Checkable
        include Formular::Elements::Module
        include Collection
        include Labels

        add_option_keys :control_label_options, :label_options, :label

        set_default :checked, 'checked', if: :is_checked?

        module InstanceMethods
          def checkable_label
            label_options[:content] = if has_label?
                                        "#{to_html(context: :default)} #{label_text}"
                                      else
                                        to_html(context: :default).to_s
                                      end

            Formular::Elements::Label.(label_options).to_s
          end

          def group_label
            return '' unless has_group_label?
            label_opts = Attributes[options[:label_options]]
            label_opts[:content] = options[:label]
            builder.checkable_group_label(label_opts).to_s
          end

          def has_group_label?
            collection.size > 1 && !options[:label].nil?
          end

          def collection
            unless collection?
              options[:label_options] = options[:control_label_options]
              return [self]
            end

            base_options = collection_base_options

            @collection ||= options[:collection].map do |item|
              opts = collection_base_options.dup
              opts[:value] = item.send(options[:value_method])
              opts[:label] = item.send(options[:label_method])

              opts[:id] = if attributes[:id]
                            "#{attributes[:id]}_#{opts[:value]}"
                          else
                            "#{attribute_name || attributes[:name].gsub('[]', '')}_#{opts[:value]}"
                          end

              self.class.(opts)
            end<commit_msg>and a little more tidying of checkable code<commit_after>require 'formular/elements/module'
require 'formular/elements/modules/collection'
require 'formular/elements/modules/labels'

module Formular
  module Elements
    module Modules
      # this module is used to correctly set the :checked attribute
      # based on the reader value.
      # It also provides an API to assist in generating checkable html (e.g. checkable labels)
      # and create collections of checkable controls from an enumerable variable.
      module Checkable
        include Formular::Elements::Module
        include Collection
        include Labels

        add_option_keys :control_label_options, :label_options, :label

        set_default :checked, 'checked', if: :is_checked?

        module InstanceMethods
          def checkable_label
            label_options[:content] = if has_label?
                                        "#{to_html(context: :default)} #{label_text}"
                                      else
                                        to_html(context: :default).to_s
                                      end

            Formular::Elements::Label.(label_options).to_s
          end

          def group_label
            return '' unless has_group_label?
            label_options[:content] = options[:label]
            builder.checkable_group_label(label_options).to_s
          end

          def has_group_label?
            collection.size > 1 && !options[:label].nil?
          end

          def collection
            unless collection?
              options[:label_options] = options[:control_label_options]
              return [self]
            end

            base_options = collection_base_options

            @collection ||= options[:collection].map do |item|
              opts = base_options.dup
              opts[:value] = item.send(options[:value_method])
              opts[:label] = item.send(options[:label_method])

              opts[:id] = if attributes[:id]
                            "#{attributes[:id]}_#{opts[:value]}"
                          else
                            "#{attribute_name || attributes[:name].gsub('[]', '')}_#{opts[:value]}"
                          end

              self.class.(opts)
            end
{'fraction_non_alphanumeric': 0.08598865124399825, 'fraction_numerical': 0.00043649061545176777, 'mean_word_length': 1.7134399052693903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6333750', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1072, 'n_words': 270}