wikiquote 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af585ef4dbc7d521807461df6072cae5e5ae229c
4
+ data.tar.gz: d94da4ef08a5140ec74212a354b89f3a27d1e83a
5
+ SHA512:
6
+ metadata.gz: 9f06e97c0a5ce89562a9f337283c269bae1ca1cfeeac1d57be241bc041feb38716ca0914dbf1f03ebd23980b3212d2d6ba11ea5ef615111bd71b4832fb18112d
7
+ data.tar.gz: 26722faa410ecd39e136337ba1ff100c8310750ffbb7edc9bfc8e25d5248b71b956dde78e550e24935a5cc237ad0e6379b0474829c1e64ff6951cf4ac5b53b18
@@ -1,5 +1,6 @@
1
- #!/usr/bin/env ruby
2
- require 'wikiquote'
3
- puts WikiQuote.get()
1
+ #! /usr/bin/env ruby
4
2
 
3
+ require 'wikiquote'
5
4
 
5
+ puts WikiQuote.quote
6
+ puts "-#{WikiQuote.author}"
@@ -1,19 +1,56 @@
1
- #!/usr/bin/evn ruby
1
+ #! /usr/bin/env ruby
2
2
  require 'net/http'
3
3
  require 'open-uri'
4
4
  require 'nokogiri'
5
+
5
6
  # The main wiki driver
6
- class WikiQuote
7
- # Get quote of the day from wikiquotes
7
+ module WikiQuote
8
+ # Every function should be a module_function
9
+ # so that users can run them.
10
+ extend self
11
+
12
+ # Get quote of the day from WikiQuote.
8
13
  #
9
14
  # Example:
10
15
  # >> WikiQuote.get()
11
16
  # => "Ruby rocks"
12
- def self.get()
13
- # Gets the quote of the day
14
- quote_url = 'http://en.wikiquote.org/wiki/Main_Page'
15
- quote_selector = "td , #mw-content-text div div:nth-child(1)" # Hope this remians ;)
17
+ def quote_of_the_day
18
+ quote_url = "http://en.wikiquote.org/wiki/Main_Page"
19
+
20
+ # Hope this remains ;)
21
+ quote_selector = "td , #mw-content-text div div:nth-child(1)"
22
+
16
23
  page = Nokogiri::HTML(open(quote_url).read)
17
24
  page.css(quote_selector)[3].text
18
25
  end
26
+
27
+ alias_method :get, :quote_of_the_day
28
+ alias_method :qotd, :quote_of_the_day
29
+
30
+ # Gets only the quote in the quote of the day.
31
+ #
32
+ # First, the start of the author portion of the quote of the day
33
+ # to the end of the string is removed from the future string.
34
+ # Then, the characters before any characters A-Z, a-z, or 0-9
35
+ # are removed from the start of the string, and whitespace is
36
+ # removed from the end of the string using regular expressions.
37
+ def quote
38
+ quote_of_the_day[0...second_to_last_index(quote_of_the_day, "~")].gsub(/(\A[^a-zA-z0-9]*|\s*\z)/, "")
39
+ end
40
+
41
+ # Gets the author of the quote of the day.
42
+ #
43
+ # Wikiquote contains this within tildes (~), which makes it easy to find.
44
+ # One just has to get the substring of the quote between the second to last tilde and the last tilde.
45
+ # This method gets that string (example "~ Isaac Asimov ~"),
46
+ # then removes the "~ " at the beginning of the string and
47
+ # " ~" at the end of the string, using regular expressions.
48
+ def author
49
+ quote_of_the_day[second_to_last_index(quote_of_the_day, "~")..quote_of_the_day.rindex("~")].gsub(/(\A~\s*|\s*~\z)/, "")
50
+ end
51
+
52
+ private
53
+ def second_to_last_index(string, search)
54
+ string.rindex(search, string.rindex(search) - 1)
55
+ end
19
56
  end
@@ -2,7 +2,27 @@ require 'test/unit'
2
2
  require 'wikiquote'
3
3
 
4
4
  class XKCDTest < Test::Unit::TestCase
5
- def test_XKCD_get
6
- assert_not_nil WikiQuote.get()
7
- end
5
+ def test_XKCD_get
6
+ assert WikiQuote.get
7
+ end
8
+
9
+ def test_quote
10
+ # Assert that it has the correct format,
11
+ # which includes no newlines
12
+ refute WikiQuote.quote.include?("\n")
13
+ # and has a non-whitespace first character
14
+ refute WikiQuote.quote[0][/\s/]
15
+ # and last character.
16
+ refute WikiQuote.quote[-1][/\s/]
17
+ end
18
+
19
+ def test_author
20
+ # Assert that it has the correct format,
21
+ # which includes no newlines
22
+ refute WikiQuote.author.include?("\n")
23
+ # and has a non-whitespace first character
24
+ refute WikiQuote.author[0][/\s/]
25
+ # and last character.
26
+ refute WikiQuote.author[-1][/\s/]
27
+ end
8
28
  end
metadata CHANGED
@@ -1,83 +1,62 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wikiquote
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Hemanth.HM
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-05-20 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2012-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: nokogiri
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 1
31
- - 5
32
- - 0
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
33
19
  version: 1.5.0
34
20
  type: :runtime
35
- version_requirements: *id001
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.0
36
27
  description: A simple gem to get Quote of the day from wikiquote.org
37
28
  email: hemanth.hm@gmail.com
38
- executables:
29
+ executables:
39
30
  - wikiquote
40
31
  extensions: []
41
-
42
32
  extra_rdoc_files: []
43
-
44
- files:
33
+ files:
45
34
  - Rakefile
46
35
  - lib/wikiquote.rb
47
36
  - bin/wikiquote
48
37
  - test/test_wikiquote.rb
49
38
  homepage: http://rubygems.org/gems/xkcd
50
39
  licenses: []
51
-
40
+ metadata: {}
52
41
  post_install_message:
53
42
  rdoc_options: []
54
-
55
- require_paths:
43
+ require_paths:
56
44
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
- version: "0"
66
- required_rubygems_version: !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
75
55
  requirements: []
76
-
77
56
  rubyforge_project:
78
- rubygems_version: 1.8.24
57
+ rubygems_version: 2.0.0
79
58
  signing_key:
80
59
  specification_version: 3
81
60
  summary: Quote of the day from wikiquote.org
82
- test_files:
61
+ test_files:
83
62
  - test/test_wikiquote.rb