-
-
Save EdwardDiehl/cafd3b0c78ad9883eefe839bdd42ddc9 to your computer and use it in GitHub Desktop.
Colors.rb – Functional programming in Ruby example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'paleta' | |
to_paleta = ->(color) { Paleta::Color.new(:hex, color) rescue nil } | |
to_div = ->(str) { | |
"<div style='font-family: sans-serif; width: 5em; height: 3em; | |
line-height: 3em; display: inline-block; text-align: center; | |
margin: 0.25em; border-radius: 0.25em; padding: 1em; | |
background: ##{str}'> | |
##{str} | |
</div>" | |
} | |
File.open('colors.html', 'w') do |file| | |
file.puts( | |
ARGF | |
.map(&:chomp) | |
.map(& to_paleta) | |
.compact | |
.sort_by(&:hue) | |
.map(&:hex) | |
.uniq | |
.map(& to_div) | |
) | |
end | |
`open colors.html` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment