<commit_before>require 'ostruct'

module Bioinform
  class Collection
    attr_reader :collection, :parameters

    # collection name is a tag name for each motif in a collection. But motif can be included in several collections so have several tags
    def initialize(parameters = {})
      @collection = []
      @parameters = OpenStruct.new(parameters)
      yield @parameters  if block_given?
    end

    def size
      collection.size
    end

    def name
      parameters.name
    end

    def to_s
      "<Collection '#{name}'>"
    end
    
    def +(other)
      result = self.class.new
      each do |pm, infos|
        result.add_pm(pm, infos)
      end
      other.each do |pm, infos|
        result.add_pm(pm, infos)
      end
      result
    end

    def add_pm(pm, info)
      pm.mark(self)
      collection << [pm, info]
      self
    end
    
    def <<(pm)
      add_pm(pm, OpenStruct.new)
    end

    def each<commit_msg>Collection#to_s created. Old method renamed as inspect<commit_after>require 'ostruct'

module Bioinform
  class Collection
    attr_reader :collection, :parameters

    # collection name is a tag name for each motif in a collection. But motif can be included in several collections so have several tags
    def initialize(parameters = {})
      @collection = []
      @parameters = OpenStruct.new(parameters)
      yield @parameters  if block_given?
    end

    def size
      collection.size
    end

    def name
      parameters.name
    end

    def inspect
      "<Collection '#{name}'>"
    end
    
    def to_s
      result = ''
      each do |pm, infos|
        result << pm.to_s << "\n"
      end
      result
    end
    
    def +(other)
      result = self.class.new
      each do |pm, infos|
        result.add_pm(pm, infos)
      end
      other.each do |pm, infos|
        result.add_pm(pm, infos)
      end
      result
    end

    def add_pm(pm, info)
      pm.mark(self)
      collection << [pm, info]
      self
    end
    
    def <<(pm)
      add_pm(pm, OpenStruct.new)
    end

    def each
{'fraction_non_alphanumeric': 0.08248423095584667, 'fraction_numerical': 0.0, 'mean_word_length': 1.9797687861271676, 'pattern_counts': {'":': 0, '<': 17, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5899465', 'n_tokens_mistral': 641, 'n_tokens_neox': 624, 'n_words': 202}