def foreground_color(background_color)
      if color = (Color::RGB.from_html(background_color) rescue false) || color = Color::CSS[background_color]
        color.brightness > 0.5 ? "black" : "white"
      else
        "black"
      end
    end
def foreground_color(background_color)
      if color = (Color::RGB.from_html(background_color) rescue false) || color = Color::CSS[background_color]
        color.brightness > 0.5 ? "black" : "white"
      else
        "black"
      end
    end
returns well readable, high-contrast foreground color ("black" or "white") based on passed background_color