Created
December 5, 2015 15:03
-
-
Save radavis/fcbb18b1efb7a6392059 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| require "open-uri" | |
| # Pull images from markdown files | |
| class Image | |
| class << self | |
| def download | |
| links.each do |link| | |
| filename = link.split("/")[-1] | |
| remote_file = open(link) | |
| IO.copy_stream(remote_file, "./image/#{filename}") | |
| end | |
| end | |
| def links | |
| result = [] | |
| regex = /\(.*\)/ | |
| markdown_image_links.each do |md_link| | |
| match = regex.match(md_link) | |
| result << match[0][1..-2] | |
| end | |
| result | |
| end | |
| def markdown_image_links | |
| result = [] | |
| markdown_files.each do |file| | |
| result |= File.readlines(file).select { |line| line =~ /(!\[.*?\]\()(.+?)(\))/ } | |
| end | |
| result | |
| end | |
| def markdown_files | |
| Dir["./**/*.md"] | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment