Permalink
Browse files

Added page.image_descriptionurls method, updated README.

  • Loading branch information...
1 parent 6df5281 commit 466d39e750189b420330d92e5941ee4e3b47b13b @kenpratt committed Jun 27, 2013
Showing with 23 additions and 11 deletions.
  1. +6 −3 README.textile
  2. +17 −8 lib/wikipedia/page.rb
View
@@ -40,15 +40,18 @@ page.images
page.image_urls
-=> ["http://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg", ...]]</code></pre>
+=> ["http://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg"]
+
+page.image_descriptionurls
+=> ["http://en.wikipedia.org/wiki/File:Getting_Things_Done.jpg"]
page.coordinates
-=> [48.853, 2.3498, "", "earth"]
+=> [48.853, 2.3498, "", "earth"]
page.templates
-=> [..., "Template:About", ...]
+=> [..., "Template:About", ...]</code></pre>
h2. Configuration
View
@@ -48,17 +48,16 @@ def image_url
page['imageinfo'].first['url'] if page['imageinfo']
end
+ def image_descriptionurl
+ page['imageinfo'].first['descriptionurl'] if page['imageinfo']
+ end
+
def image_urls
- if list = images
- filtered = list.select {|i| i =~ /^file:.+\.(jpg|jpeg|png|gif)$/i && !i.include?("LinkFA-star") }
- filtered.map do |title|
- Wikipedia.find_image( title ).image_url
- end
- end
+ image_metadata.map {|img| img.image_url }
end
- def image_descriptionurl
- page['imageinfo'].first['descriptionurl'] if page['imageinfo']
+ def image_descriptionurls
+ image_metadata.map {|img| img.image_descriptionurl }
end
def coordinates
@@ -69,6 +68,16 @@ def raw_data
@data
end
+ def image_metadata
+ unless @cached_image_metadata
+ if list = images
+ filtered = list.select {|i| i =~ /^file:.+\.(jpg|jpeg|png|gif)$/i && !i.include?("LinkFA-star") }
+ @cached_image_metadata = filtered.map {|title| Wikipedia.find_image(title) }
+ end
+ end
+ @cached_image_metadata || []
+ end
+
def templates
page['templates'].map {|c| c['title'] } if page['templates']
end

0 comments on commit 466d39e

Please sign in to comment.