- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3
 
Auto color data #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Auto color data #23
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@ericgpks you may be interested in this.
| }.freeze | ||
| end | ||
| end | ||
| require_relative "./color_data/matplotlib" | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the preceding ./:
| require_relative "./color_data/matplotlib" | |
| require_relative "color_data/matplotlib" | 
| require "open-uri" | ||
| require "nokogiri" | ||
| 
               | 
          ||
| module GetColors | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about CSS4ColorDataGenerator?
| 
               | 
          ||
| class CSS4 | ||
| def initialize | ||
| @colordata = [] | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify this to @data.
| @colordata = [] | ||
| end | ||
| 
               | 
          ||
| def get_data | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about parse?
| doc = Nokogiri::HTML(html) | ||
| table = doc.css("table.named-color-table").first | ||
| table.css("tbody").children.each do |kid| | ||
| colorname = kid.css("dfn").text.strip | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify this to name.
| end | ||
| 
               | 
          ||
| def dump_file(filename) | ||
| File.open(filename, "w") do |fh| | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened file is a File object not file handler. So file is better than fh:
| File.open(filename, "w") do |fh| | |
| File.open(filename, "w") do |file| | 
| CSS4FOOTER | ||
| end | ||
| 
               | 
          ||
| def dump_file(filename) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about generate?
| end | ||
| 
               | 
          ||
| def header(fh) | ||
| fh.puts <<~CSS4HEADER | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove CSS4 prefix because this class is for CSS4:
| fh.puts <<~CSS4HEADER | |
| fh.puts <<~HEADER | 
| css4.dump_file("lib/colors/color_data/css4.rb") | ||
| end | ||
| 
               | 
          ||
| desc "Get color data files from the web, per issue #8" | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to refer #8 here.
| desc "Get color data files from the web, per issue #8" | |
| desc "Get color data files from the web" | 
| end | ||
| 
               | 
          ||
| desc "Get color data files from the web, per issue #8" | ||
| task :get_colors => [:get_xkcd, :get_css4] | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about colors:generate?
| task :get_colors => [:get_xkcd, :get_css4] | |
| namespace :colors do | |
| namespace :generate do | |
| task :xkcd do | |
| # ... | |
| end | |
| task :css4 do | |
| # ... | |
| end | |
| end | |
| task :generate => [:xkcd, :css4] | |
| end | 
| 
           Could you create a separated pull request that separates   | 
    
Resolves issue #8 by adding rake-tasks to get XKCD and CSS4 colors from the URIs listed in the documentation.
It is worth noting that:
colors/color_data.rbinto separate files, in preparation for some portions (xkcd.rb, css4.rb) to be autogenerated.