<commit_before>require 'json'
require 'Cleaner'

class Lights
  include Enumerable

  def initialize(avatar)
    @avatar = avatar
  end

  attr_reader :avatar

  def each
    # avatar.lights.each
    lights.each_with_index { |light,n| yield self[n,light] if block_given? }
  end

  def [](n, light = nil)
    # avatar.lights[6]
    Light.new(avatar, light || lights[n])
  end

  def length
    lights.length
  end

  def latest
    self[length-1]
  end

  #def <<(light)
  #  ...
  #  @lights = nil  (reset cache)
  #end

private

  def lights
    return @lights ||= JSON.parse(clean(avatar.dir.read('increments.json')))
  end

  include Cleaner

end
<commit_msg>refactoring<commit_after>require 'json'
require 'Cleaner'

class Lights
  include Enumerable

  def initialize(avatar)
    @avatar = avatar
  end

  def each
    # avatar.lights.each
    lights.each_with_index { |light,n| yield self[n,light] if block_given? }
  end

  def [](n, light = nil)
    # avatar.lights[6]
    Light.new(@avatar, light || lights[n])
  end

  def length
    lights.length
  end

  def latest
    self[length-1]
  end

  #def <<(light)
  #  ...
  #  @lights = nil  (reset cache)
  #end

private

  def lights
    return @lights ||= JSON.parse(clean(@avatar.dir.read('increments.json')))
  end

  include Cleaner

end

{'fraction_non_alphanumeric': 0.1204911742133538, 'fraction_numerical': 0.0030698388334612432, 'mean_word_length': 2.880952380952381, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3907115', 'n_tokens_mistral': 498, 'n_tokens_neox': 466, 'n_words': 116}