Sha256: ae98b097c2e9384e6ba7ac2a5fdf9f8c211d246be61c1e0c2c3280bede1ab46d
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
module GridGenerator class FaceParser COLOURS = { 'w' => '#ffffff', 'y' => '#ffff00', 'b' => '#0000ff', 'g' => '#00ff00', 'r' => '#ff0000', 'o' => '#ffb000', 'gr' => '#808080', 'br' => '#804000', 's' => '#8080ff', 'l' => '#80ff80', 'p' => '#800080', 'pi' => '#ff8080', 'fu' => "#f0f0f0", # face up 'ff' => "#d0d0d0", # face front 'fr' => "#b0b0b0" # face right } OPACITY = { full: 1, faded: 0.4 } def initialize(string) @string = string end def single? @string.length == 1 end attr_reader :string def parse if single? parse_char(string) else parse_array(string) end end def parse_char(char) if char == '-' nil else colour = COLOURS[char.downcase] opacity = OPACITY[(/[[:upper:]]/.match(char) ? :full : :faded)] { colour: colour, opacity: opacity } end end def parse_array(str) str.split(/\\n/).map do |line| line.split(',').map(&:strip).map do |col| parse_char(col) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
grid_generator-0.1.5 | lib/grid_generator/face_parser.rb |