<commit_before># encoding: utf-8



module SwissMatch

  # Represents a swiss community.
  # Swiss communities are identified by their community number (BFSNR).
  class Community

    # @return [Integer]
    #   A unique, never recycled identification number.
    #   Also known as BFSNR.
    attr_reader :community_number

    # @return [String]
    #   The official name of the community.
    attr_reader :name

    # @return [SwissMatch::Canton]
    #   The canton this community belongs to.
    attr_reader :canton

    # @return [SwissMatch::Community]
    #   The community this community is considered to be an agglomeration of.
    #   Note that a main community will reference itself.
    attr_reader :agglomeration

    # @param [Integer] community_number
    #   The identification number of the community, also known as BFSNR.
    # @param [String] name
    #   The official name of the community
    # @param [SwissMatch::Canton] canton
    #   The canton this community belongs to
    # @param [SwissMatch::Community]
    #   The community this community is considered to be an agglomeration of.
    #   Note that a main community will reference itself.
    def initialize(community_number, name, canton, agglomeration)
      @community_number = community_number
      @name             = name
      @canton           = canton
      @agglomeration    = agglomeration == :self ? self : agglomeration
    end

    alias to_s name

    def to_hash
      {
        :community_number => @community_number,
        :name             => @name,
        :canton           => @canton,
        :agglomeration    => @agglomeration,
      }
    end

    def hash
      [self.class, @community_number].hash
    end

    def eql?(other)
      self.class == other.class && @community_number == other.community_number
    end

    # @return [String]
    # @see Object#inspect
    def inspect
      sprintf "\#<%s:%014x %s, BFSNR %d>", self.class, object_id, self, @community_number
    end
  end
end<commit_msg>Changed how SwissMatch::Community#to_hash works, it now will emit a "flat" datastructure per default, allowing to retain referenced objects optionally (just as SwissMatch::ZipCode#to_hash since ec0dcd1ca6223a927b4f92058745f1cc0c33df10).<commit_after># encoding: utf-8



module SwissMatch

  # Represents a swiss community.
  # Swiss communities are identified by their community number (BFSNR).
  class Community

    # @return [Integer]
    #   A unique, never recycled identification number.
    #   Also known as BFSNR.
    attr_reader :community_number

    # @return [String]
    #   The official name of the community.
    attr_reader :name

    # @return [SwissMatch::Canton]
    #   The canton this community belongs to.
    attr_reader :canton

    # @return [SwissMatch::Community]
    #   The community this community is considered to be an agglomeration of.
    #   Note that a main community will reference itself.
    attr_reader :agglomeration

    # @param [Integer] community_number
    #   The identification number of the community, also known as BFSNR.
    # @param [String] name
    #   The official name of the community
    # @param [SwissMatch::Canton] canton
    #   The canton this community belongs to
    # @param [SwissMatch::Community]
    #   The community this community is considered to be an agglomeration of.
    #   Note that a main community will reference itself.
    def initialize(community_number, name, canton, agglomeration)
      @community_number = community_number
      @name             = name
      @canton           = canton
      @agglomeration    = agglomeration == :self ? self : agglomeration
    end

    alias to_s name

    def to_hash(retain_references=false)
      if retain_references then
        canton        = @canton
        agglomeration = @agglomeration
      else
        canton        = @canton && @canton.license_tag
        agglomeration = @agglomeration && @agglomeration.community_number
      end

      {
        :community_number => @community_number,
        :name             => @name,
        :canton           => canton,
        :agglomeration    => agglomeration,
      }
    end

    def hash
      [self.class, @community_number].hash
    end

    def eql?(other)
      self.class == other.class && @community_number == other.community_number
    end

    # @return [String]
    # @see Object#inspect
    def inspect
      sprintf "\#<%s:%014x %s, BFSNR %d>", self.class, object_id, self, @community_number
    end
  end
end
{'fraction_non_alphanumeric': 0.07838795394154119, 'fraction_numerical': 0.0070859167404783, 'mean_word_length': 2.599203187250996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4010194', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1279, 'n_words': 417}