Class: Wp2hatena::Wordpress::Image
- Inherits:
-
Object
- Object
- Wp2hatena::Wordpress::Image
- Defined in:
- lib/wp2hatena/wordpress/image.rb
Instance Method Summary collapse
- #download(xml_path) ⇒ Object
-
#initialize ⇒ Image
constructor
A new instance of Image.
Constructor Details
#initialize ⇒ Image
Returns a new instance of Image.
7 8 9 |
# File 'lib/wp2hatena/wordpress/image.rb', line 7 def initialize @tmp_dir = Dir.mktmpdir end |
Instance Method Details
#download(xml_path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wp2hatena/wordpress/image.rb', line 11 def download(xml_path) open(xml_path, 'r') do |fp| fp.each_line do |line| line.match(/<a.*?href="([^"]+?)"><img.*?src="(.+?)".*?><\/a>/) do |md| image_url = nil image_url = md[2] if md[2].match(/.+\.(jpg|jpeg|gif|png|bmp)\Z/) image_url = md[1] if md[1].match(/.+\.(jpg|jpeg|gif|png|bmp)\Z/) data = { file_path: fetch_image(image_url), width: match_width(line), height: match_height(line), html_tag: line, } yield data end end end end |