Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

ruby colors program

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am new to ruby programming(like 4 classes of teaching). I am
writing a ruby script that extracts hexadecimal color codes out of a
Cascading Style Sheet (CSS) file. the script takes 2 command line
arguments. A location of css file and a filename to write out the
report. the script generates a html page that displays color swatches
with their RGB and hexadecimal values. I need help on how to open files
and match colors and output it in html page. i have to match the sample output provided below

My code:









A sample CSS file:


sample output

 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

I've been doing Ruby for about seven months now ... (phrasing!) ... so I'm not exactly an expert either. I've been programing a long, long time though, and some concepts are universal.

Basically, you're asking us to solve a homework problem for you, which we don't do, but we can nudge in the right direction. Your short script shows (on line 7) the correct regex for parsing out color strings, but actually uses a different one for some reason. The way I'd start with this is ignore the output file, and just build up a hash keyed by the colors you parse out, and counting how many times you've seen each one. Get that done, and then we can talk about formatting the output.
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic