urban 0.0.6 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011 Thomas Miller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = Urban
2
+
3
+ Urban is a command line tool that allows you to look up definitions or pull a
4
+ random definition from {Urban Dictionary}[http://www.urbandictionary.com].
5
+
6
+ * {Git}[http://github.com/tmiller/urban]
7
+ * {Bug Tracker}[http://github.com/tmiller/urban/issues]
8
+
9
+ == Installation
10
+
11
+ With Rubygems:
12
+
13
+ $ sudo gem install urban
14
+
15
+ With git and local working copy
16
+
17
+ $ git clone git://github.com/tmiller/urban.git
18
+ $ cd urban
19
+ $ sudo rake install
20
+
21
+ == Usage
22
+
23
+ === 1. Look up a word
24
+
25
+ $ urban cookie
26
+
27
+ === 2. Random word
28
+
29
+ $ urban
30
+
31
+ == To Do
32
+
33
+ * Write Tests
34
+ * Implement looking up a word
35
+ * Document with {YARD}[http://yardoc.org]
36
+ * Implement -l switch to list all definitions
37
+
38
+ == Test words for formatting
39
+
40
+ The first definitions on these words were show to
41
+ have problems displaying in the terminal. They are to be used to write tests.
42
+
43
+ * {mina}[http://www.urbandictionary.com/define.php?term=minal]
44
+ * {ugly-hot}[http://www.urbandictionary.com/define.php?term=ugly-hot]
45
+ * {bolen}[http://www.urbandictionary.com/define.php?term=bolen]
46
+ * {chinalian}[http://www.urbandictionary.com/define.php?term=chinalian]
47
+
48
+ Copyright (c) 2011 Thomas Miller. See LICENSE for details.
data/bin/urban CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require 'urban/version'
4
- require 'urban'
5
+ require 'urban/cli'
5
6
 
6
- Urban.random
7
+ Urban.process
data/lib/urban.rb CHANGED
@@ -1,28 +1,2 @@
1
- require "urban/version"
2
-
3
- require 'open-uri'
4
- require 'nokogiri'
5
- require 'active_support/core_ext/string/inflections'
6
-
7
- module Urban
8
- def self.random
9
- url = URI.encode('http://www.urbandictionary.com/random.php')
10
- doc = Nokogiri.HTML(open(url))
11
- word = clean_text(doc.at_css('.word')).humanize
12
- definition = clean_text(doc.at_css('.definition')).gsub(/\s{2,}/, ' ').gsub(/^\s*\w|\.\s+\w/) { |char| char.upcase }
13
- puts "#{word}: #{definition}"
14
- end
15
-
16
- private
17
- def self.clean_text(node_set)
18
- node_set.children.each do |node|
19
- if node.name == 'br'
20
- node.remove
21
- else
22
- node.content = node.content.strip << ' '
23
- end
24
- end
25
- return node_set.content.strip.gsub(/ \./, '.')
26
- end
27
-
28
- end
1
+ require 'urban/version'
2
+ require 'urban/dictionary'
data/lib/urban/cli.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'urban/dictionary'
2
+
3
+ module Urban
4
+
5
+ def process
6
+ begin
7
+ result = ARGV.first ? define(ARGV.first) : random
8
+ puts "#{result[:word]}: #{result[:definition]}"
9
+ rescue
10
+ puts "ERROR: #{ARGV.first.capitalize} not found!"
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,53 @@
1
+ require 'urban/version'
2
+
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ module Urban
7
+ extend self
8
+
9
+ URL = 'http://www.urbandictionary.com'
10
+
11
+ def random
12
+ get_definition(query(:random))
13
+ end
14
+
15
+ def define(word)
16
+ get_definition(query(:define, word))
17
+ end
18
+
19
+ def get_definition(document)
20
+ word = wordize(node_to_s(document.at_css('.word')))
21
+ definition = definitionize(node_to_s(document.at_css('.definition')))
22
+ return { word: word, definition: definition }
23
+ end
24
+
25
+ def query(type, word = nil)
26
+ query = "#{type.to_s}.php"
27
+ query << "?term=#{word}" if word
28
+ doc = Nokogiri.HTML(open(URI.encode("#{URL}/#{query}")))
29
+ end
30
+
31
+ def node_to_s(node_set)
32
+ node_set.children.each do |node|
33
+ case node.name
34
+ when 'br'
35
+ node.previous.content = node.previous.content << "\n" if node.previous
36
+ node.remove
37
+ end
38
+ end
39
+ return node_set.content.strip.gsub(/\r/, "\n")
40
+ end
41
+
42
+ def capitalize(string, pattern)
43
+ return string.gsub(pattern, &:upcase).gsub(/\s{2,}/, ' ')
44
+ end
45
+
46
+ def wordize(string)
47
+ return capitalize(string, /^\s*\w/)
48
+ end
49
+
50
+ def definitionize(string)
51
+ return capitalize(string, /^\s*\w|\.\s+\w/)
52
+ end
53
+ end
data/lib/urban/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Urban
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.11'
3
3
  end
data/urban.gemspec CHANGED
@@ -5,13 +5,12 @@ require 'urban/version'
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'urban'
7
7
  s.version = Urban::VERSION
8
- s.authors = ['Tom Miller']
8
+ s.authors = ['Thomas Miller']
9
9
  s.email = ['jackerran@gmail.com']
10
10
  s.homepage = 'https://github.com/tmiller/urban'
11
- s.summary = %q{A command line tool to output a random Urban Dictionary entry}
12
- s.description = %q{Currently only a beta command line tool that outputs a random urban dictionary entry. In
13
- the future there are plans to add other features to the tool such as search
14
- and word of the day. There will also be an api to use in your projects.}
11
+ s.summary = %q{A command line tool that interfaces with Urban Dictionary.}
12
+ s.description = %q{Urban is a command line tool that allows you to look up definitions
13
+ or pull a random definition from Urban Dictionary.}
15
14
 
16
15
  s.rubyforge_project = 'urban'
17
16
 
@@ -21,7 +20,5 @@ Gem::Specification.new do |s|
21
20
  s.require_paths = ['lib']
22
21
 
23
22
  s.add_dependency 'nokogiri'
24
- s.add_dependency 'i18n'
25
- s.add_dependency 'activesupport'
26
23
  s.add_development_dependency 'ruby-debug19'
27
24
  end
metadata CHANGED
@@ -2,15 +2,15 @@
2
2
  name: urban
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.11
6
6
  platform: ruby
7
7
  authors:
8
- - Tom Miller
8
+ - Thomas Miller
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-12 00:00:00 -05:00
13
+ date: 2011-08-16 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -24,43 +24,20 @@ dependencies:
24
24
  version: "0"
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: i18n
29
- prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
36
- type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: activesupport
40
- prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
47
- type: :runtime
48
- version_requirements: *id003
49
27
  - !ruby/object:Gem::Dependency
50
28
  name: ruby-debug19
51
29
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
30
+ requirement: &id002 !ruby/object:Gem::Requirement
53
31
  none: false
54
32
  requirements:
55
33
  - - ">="
56
34
  - !ruby/object:Gem::Version
57
35
  version: "0"
58
36
  type: :development
59
- version_requirements: *id004
37
+ version_requirements: *id002
60
38
  description: |-
61
- Currently only a beta command line tool that outputs a random urban dictionary entry. In
62
- the future there are plans to add other features to the tool such as search
63
- and word of the day. There will also be an api to use in your projects.
39
+ Urban is a command line tool that allows you to look up definitions
40
+ or pull a random definition from Urban Dictionary.
64
41
  email:
65
42
  - jackerran@gmail.com
66
43
  executables:
@@ -73,10 +50,13 @@ files:
73
50
  - .gitignore
74
51
  - .rvmrc
75
52
  - Gemfile
76
- - README
53
+ - LICENSE
54
+ - README.rdoc
77
55
  - Rakefile
78
56
  - bin/urban
79
57
  - lib/urban.rb
58
+ - lib/urban/cli.rb
59
+ - lib/urban/dictionary.rb
80
60
  - lib/urban/version.rb
81
61
  - urban.gemspec
82
62
  has_rdoc: true
@@ -106,6 +86,6 @@ rubyforge_project: urban
106
86
  rubygems_version: 1.6.2
107
87
  signing_key:
108
88
  specification_version: 3
109
- summary: A command line tool to output a random Urban Dictionary entry
89
+ summary: A command line tool that interfaces with Urban Dictionary.
110
90
  test_files: []
111
91
 
data/README DELETED
@@ -1,6 +0,0 @@
1
- Known words with bad markup for testing
2
- http://www.urbandictionary.com/define.php?term=minal
3
- http://www.urbandictionary.com/define.php?term=ugly-hot
4
- http://www.urbandictionary.com/define.php?term=bolen
5
- http://www.urbandictionary.com/define.php?term=chinalian
6
-