Skip to content

Instantly share code, notes, and snippets.

@radavis
Created December 5, 2015 15:03
Show Gist options
  • Select an option

  • Save radavis/fcbb18b1efb7a6392059 to your computer and use it in GitHub Desktop.

Select an option

Save radavis/fcbb18b1efb7a6392059 to your computer and use it in GitHub Desktop.
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