<commit_before>module Lodo
  class String
    LED_COUNT = 100

    def initialize
      @device = Core.open_device
      @buffer = Core::Buffer.new
      @buffer_cache = {} # TODO replace with retrieval from C buffer?

      Core.set_gamma 2.2, 2.2, 2.2
      raise "Device failed to open" if @device <= 0

      spi_status = Core.spi_init(@device)
      raise "SPI failed to start" if spi_status != 0

      tcl_status = Core.tcl_init(@buffer.pointer, LED_COUNT)
      raise "TCL failed to start" if tcl_status != 0
    end

    def []= (led_number, color)
      Core.write_gamma_color_to_buffer(@buffer.pointer, led_number, color[:red], color[:green], color[:blue])
      @buffer_cache[led_number] = color
    end

    def [] (led_number)
      @buffer_cache[led_number]
    end

    def save
      Core.send_buffer(@device, @buffer.pointer)
    end

    def each
      LED_COUNT.times do |led_number|
        color = yield(led_number)
        self[led_number] = color
      end
    end

    def reset
      self.each do |light_number|
        {red: 0, green: 0, blue: 0}
      end
      save
    end
  end
end<commit_msg>Update String to use internal reference for Core<commit_after>module Lodo
  class String
    LED_COUNT = 100

    def initialize
      @core = Core
      @device = @core.open_device
      @buffer = @core::Buffer.new
      @buffer_cache = {} # TODO replace with retrieval from C buffer?

      @core.set_gamma 2.2, 2.2, 2.2
      raise "Device failed to open" if @device <= 0

      spi_status = @core.spi_init(@device)
      raise "SPI failed to start" if spi_status != 0

      tcl_status = @core.tcl_init(@buffer.pointer, LED_COUNT)
      raise "TCL failed to start" if tcl_status != 0
    end

    def []= (led_number, color)
      @core.write_gamma_color_to_buffer(@buffer.pointer, led_number, color[:red], color[:green], color[:blue])
      @buffer_cache[led_number] = color
    end

    def [] (led_number)
      @buffer_cache[led_number]
    end

    def save
      @core.send_buffer(@device, @buffer.pointer)
    end

    def each
      LED_COUNT.times do |led_number|
        color = yield(led_number)
        self[led_number] = color
      end
    end

    def reset
      self.each do |light_number|
        {red: 0, green: 0, blue: 0}
      end
      save
    end
  end
end
{'fraction_non_alphanumeric': 0.09917713295799047, 'fraction_numerical': 0.0129926375054136, 'mean_word_length': 2.4323922734026744, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3468533', 'n_tokens_mistral': 789, 'n_tokens_neox': 742, 'n_words': 210}