jok 0.0.1 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d03420a3d120a88ec9eda060bba6daf1265cd4c7
4
- data.tar.gz: 10fabd8ef998aa43ccffcdee08615caad0ebaf95
3
+ metadata.gz: c401ed8b4203e250af4792edff27e709d5aaf439
4
+ data.tar.gz: 4a9bccbc21e431fc54468b8fcc03f97b04c0f3d8
5
5
  SHA512:
6
- metadata.gz: 26549a6491789ff0897b289c3a23e478b367a4d8d44cbc72b43ee0b8008b3785a3fbf166479d3ea90b521bf1d18a5d1f8d4dd09320e2b6595a28a10fe66dcd8a
7
- data.tar.gz: 19c121c46af65d5260155278022544c2abad87dc743bec27d62585d3b516c4080923d108e0854a7d70ba5ad90c34fae0d4c00d38351c758c00a21ba5de9ba330
6
+ metadata.gz: 501e0f5fd2db69621358614dcf4f10ff249c1bd4e3a256bd1866da9b562a61ad8c6b27155c42d59740b2c221323817e970aa9b982863d3eddaa101968afa91cd
7
+ data.tar.gz: 3bc40078846771031973af0bfede8bb117da117e6eb1d95c4dce57684528e3c3dd3c07bbdb044c588b1be0fd8e56b3770b5fb6802bb632af30f3c8058af4a7fe
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Jok
2
2
 
3
- Jok will bring you a good laugh.
3
+ Jok will bring you a good laugh. But please do use it responsively.
4
4
 
5
5
  ## Installation
6
6
 
@@ -38,12 +38,26 @@ module Jok
38
38
  private
39
39
 
40
40
  def dom(method="")
41
- response_body = HTTParty.get("#{BASE_URI}/#{method.gsub("_", "-")}")
42
- dom = Nokogiri::HTML(response_body)
41
+ topic = "#{BASE_URI}/#{method.gsub("_", "-")}"
42
+ response_body = HTTParty.get(topic)
43
+ dom_tree = Nokogiri::HTML(response_body)
44
+
45
+ return dom_tree if method == ""
46
+
47
+ pagination_items = dom_tree.xpath('//div[@class="pagination"]/ul/li').map(&:text).map(&:strip)
48
+
49
+ if pagination_items.length > 0
50
+ selected_item = pagination_items[srand % (pagination_items.length - 1)]
51
+
52
+ response_body = HTTParty::get("#{topic}/#{selected_item}")
53
+ Nokogiri::HTML(response_body)
54
+ else
55
+ dom_tree
56
+ end
43
57
  end
44
58
 
45
59
  def joke(topic="")
46
- dom(topic).xpath('//div[@class="joke3-pop-box"]/p').map(&:text).map(&:strip)
60
+ dom(topic).xpath('//div[@class="joke3-pop-box"]/p[substring-before(@id, "_") = "joke"]').map(&:text).map(&:strip)
47
61
  end
48
62
  end
49
63
  end
data/lib/jok/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jok
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/test/jok_test.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  require "minitest/autorun"
2
2
 
3
3
  describe Jok, "Hello world" do
4
- it "works" do
5
- Jok::HELLO_WORLD.must_equal 1
4
+ it "#list" do
5
+ Jok.list.must_be_instance_of Array
6
+ end
7
+
8
+ it "#da" do
9
+ Jok.da.must_be_instance_of String
6
10
  end
7
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jingkai He