<commit_before>module SpecHelpers
  def html_to_rgb(string, base_color)
    hash = Digest::SHA1.hexdigest string

    hue_offset     = GeoPattern::PatternHelpers.map(GeoPattern::PatternHelpers.hex_val(hash, 14, 3), 0, 4095, 0, 359)
    sat_offset     = GeoPattern::PatternHelpers.hex_val(hash, 17, 1)
    base_color     = Color::RGB.from_html(base_color).to_hsl
    base_color.hue = base_color.hue - hue_offset;

    if (sat_offset % 2 == 0)
      base_color.saturation = base_color.saturation + sat_offset
    else
      base_color.saturation = base_color.saturation - sat_offset
    end

    rgb = base_color.to_rgb

    r = (rgb.r * 255).round
    g = (rgb.g * 255).round
    b = (rgb.b * 255).round

    format("rgb(%d, %d, %d)", r, g, b)
  end
end

RSpec.configure do |config|
  config.include SpecHelpers
end
<commit_msg>Refactored helpers to support both base_color and color<commit_after>module SpecHelpers
  def html_to_rgb(color)
    generate_rgb_string(Color::RGB.from_html(color))
  end

  def html_to_rgb_for_string(string, base_color)
    hash = Digest::SHA1.hexdigest string

    hue_offset     = GeoPattern::PatternHelpers.map(GeoPattern::PatternHelpers.hex_val(hash, 14, 3), 0, 4095, 0, 359)
    sat_offset     = GeoPattern::PatternHelpers.hex_val(hash, 17, 1)
    base_color     = Color::RGB.from_html(base_color).to_hsl
    base_color.hue = base_color.hue - hue_offset;

    if (sat_offset % 2 == 0)
      base_color.saturation = base_color.saturation + sat_offset
    else
      base_color.saturation = base_color.saturation - sat_offset
    end

    generate_rgb_string(base_color.to_rgb)
  end

  def generate_rgb_string(rgb)
    r = (rgb.r * 255).round
    g = (rgb.g * 255).round
    b = (rgb.b * 255).round

    format("rgb(%d, %d, %d)", r, g, b)
  end
end

RSpec.configure do |config|
  config.include SpecHelpers
end

{'fraction_non_alphanumeric': 0.11279826464208242, 'fraction_numerical': 0.02928416485900217, 'mean_word_length': 3.489051094890511, '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': '203110', 'n_tokens_mistral': 728, 'n_tokens_neox': 667, 'n_words': 137}