<commit_before>module TMX
  class Layer
    attr_reader :properties
    attr_reader :width, :height
    
    def initialize map, data, properties
      @map        = WeakRef.new map
      @properties = properties.dup
      
      @width  = @properties.delete(:width)     or raise ArgumentError, "layer width is required"
      @height = @properties.delete(:height)    or raise ArgumentError, "layer height is required"
      
      @tile_ids = case data
        when String then data.unpack('V*')
        when Array  then data.dup
        when nil    then Array.new @width * @height, 0
        else raise ArgumentError, "data must be a binary string or an array of integers"
        end
    end # initialize
    
    def map; @map.__getobj__ end
    
    def [] x, y
      raise IndexError unless x_range.include? x and y_range.include? y
      @tile_ids[offset(x, y)]
    end
    
    def []= x, y, id
      raise IndexError unless x_range.include? x and y_range.include? y
      @tile_ids[offset(x, y)] = id
    end
    
    def x_range; 0...@width  end
    def y_range; 0...@height end
    
    private
    
    def offset x, y
      x + y * @width
    end
    
  end # Layer
end<commit_msg>Layer#each_tile_id for my own nefarious purposes<commit_after>module TMX
  class Layer
    attr_reader :properties
    attr_reader :width, :height
    
    def initialize map, data, properties
      @map        = WeakRef.new map
      @properties = properties.dup
      
      @width  = @properties.delete(:width)     or raise ArgumentError, "layer width is required"
      @height = @properties.delete(:height)    or raise ArgumentError, "layer height is required"
      
      @tile_ids = case data
        when String then data.unpack('V*')
        when Array  then data.dup
        when nil    then Array.new @width * @height, 0
        else raise ArgumentError, "data must be a binary string or an array of integers"
        end
    end # initialize
    
    def map; @map.__getobj__ end
    
    def [] x, y
      raise IndexError unless x_range.include? x and y_range.include? y
      @tile_ids[offset(x, y)]
    end
    
    def []= x, y, id
      raise IndexError unless x_range.include? x and y_range.include? y
      @tile_ids[offset(x, y)] = id
    end
    
    def each_tile_id &block
      y_range.each do |y|
        x_range.each do |x|
          yield x, y, @tile_ids[offset(x, y)]
        end
      end
    end # each_tile_id
    
    def x_range; 0...@width  end
    def y_range; 0...@height end
    
    private
    
    def offset x, y
      x + y * @width
    end
    
  end # Layer
end
{'fraction_non_alphanumeric': 0.08342945021145713, 'fraction_numerical': 0.002306805074971165, 'mean_word_length': 2.0326340326340326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2307823', 'n_tokens_mistral': 819, 'n_tokens_neox': 804, 'n_words': 274}