Skip to content

Instantly share code, notes, and snippets.

@hiroshiro
Created February 23, 2014 15:56
Show Gist options
  • Select an option

  • Save hiroshiro/9173148 to your computer and use it in GitHub Desktop.

Select an option

Save hiroshiro/9173148 to your computer and use it in GitHub Desktop.
URLのリンクにjpgのファイルがあればsave_file()メソッド使いファイルを保存する。save_extract_jpg() Rubyのメソッド。
##
# jpgがあればURLをセーブする。
##
def save_extract_jpg(doc)
(doc/:img).each do |link|
->(url){ save_file(url) }.call(link[:src].to_s) if link[:src] =~ /.jpg/
end
end
save_extract_jpg(doc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment