xkcd 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/xkcd.rb +12 -1
  2. metadata +3 -3
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'nokogiri'
3
3
  require 'open-uri'
4
+ require 'json'
5
+
4
6
  # The main XKCD driver
5
7
  class XKCD
6
8
  # Get img/comic URL from xkcd
@@ -19,11 +21,20 @@ class XKCD
19
21
  class << XKCD
20
22
  alias_method :get, :comic
21
23
  end
22
-
24
+
25
+ =begin
23
26
  def self.img
24
27
  img = Nokogiri::HTML(open('http://dynamic.xkcd.com/random/comic/')).css('#comic img')[0]
25
28
  img_url = img.attributes["src"].value
26
29
  img_title = img.attributes["title"].value
27
30
  "#{img_title} : #{img_url}"
28
31
  end
32
+ =end
33
+ def self.img
34
+ max = JSON.parse(open('http://xkcd.com/info.0.json').read)["num"]
35
+ comic_num = Random.rand(max)
36
+ comic_num = 1 if comic_num == 404 # Avoid 404th comic ;)
37
+ comic = JSON.parse(open("http://xkcd.com/#{random_comic}/info.0.json").read)
38
+ "#{comic['alt']} : #{comic['img']}"
39
+ end
29
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xkcd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &73383140 !ruby/object:Gem::Requirement
16
+ requirement: &73470780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -24,7 +24,7 @@ dependencies:
24
24
  version: 1.5.0
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *73383140
27
+ version_requirements: *73470780
28
28
  description: A simple gem to get random img/comic url from xkcd
29
29
  email: hemanth.hm@gmail.com
30
30
  executables: []