quoth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/evn ruby
2
+ require 'net/http'
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ # The main random wiki driver
7
+ module Quoth
8
+ FILE_NAME = File.dirname(__FILE__)+'/data/data.html'
9
+ URL = 'http://en.wikiquote.org/wiki/Wikiquote:Quote_of_the_Day'
10
+
11
+ # Get a random quote of the day from wikiquotes
12
+ #
13
+ # Example:
14
+ # >> RandomWikiQuote.get
15
+ # => "Ruby rocks"
16
+ def self.get
17
+ quotes.sample
18
+ end
19
+
20
+ def self.get_first
21
+ quotes.first
22
+ end
23
+
24
+ def self.refresh_quotes
25
+ File.open(FILE_NAME, 'w') do |file|
26
+ open(URL) do |uri|
27
+ file.write(uri.read)
28
+ end
29
+ end
30
+ "Successfully refreshed quotes from #{URL}."
31
+ end
32
+
33
+ private
34
+
35
+ def self.quotes
36
+ refresh_quotes unless File.exist? FILE_NAME
37
+ Nokogiri::HTML(File.read(FILE_NAME)).css('dd,li').map &:text
38
+ end
39
+
40
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ['Alister Scott']
4
+ gem.email = ['alister.scott@gmail.com']
5
+ gem.description = 'Pseudo random quote of the day from wikiquotes'
6
+ gem.summary = 'Pseudo random quote of the day from wikiquotes'
7
+ gem.homepage = ""
8
+ gem.files = `git ls-files`.split($\)
9
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
10
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
11
+ gem.name = 'quoth'
12
+ gem.require_paths = ['lib']
13
+ gem.version = '0.0.1'
14
+ gem.add_dependency 'nokogiri'
15
+ gem.add_development_dependency 'rspec'
16
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'quoth'
3
+
4
+ describe Quoth do
5
+ it 'returns a quote' do
6
+ Quoth.get_first.should == '11. I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character. ~ Martin Luther King (This was the first "Quote of the Day" at Wikiquote, selected by Nanobug on 11 July 2003.)'
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quoth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alister Scott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &70181946716740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70181946716740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70181946716180 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70181946716180
36
+ description: Pseudo random quote of the day from wikiquotes
37
+ email:
38
+ - alister.scott@gmail.com
39
+ executables:
40
+ - quoth
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - .rvmrc
46
+ - Gemfile
47
+ - LICENSE
48
+ - README.md
49
+ - Rakefile
50
+ - bin/quoth
51
+ - lib/data/data.html
52
+ - lib/quoth.rb
53
+ - quoth.gemspec
54
+ - spec/quoth_spec.rb
55
+ homepage: ''
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.17
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Pseudo random quote of the day from wikiquotes
79
+ test_files:
80
+ - spec/quoth_spec.rb