urban_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/urban_api.rb +14 -6
  2. data/urban_api.gemspec +2 -2
  3. metadata +3 -3
@@ -2,9 +2,18 @@ require 'nokogiri'
2
2
  require 'faraday'
3
3
 
4
4
  class UrbanAPI
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
 
7
7
  class Definition < Struct.new(:definition, :example)
8
+ def self.create(def_node, example_node)
9
+ new(extract_from(def_node), extract_from(example_node))
10
+ end
11
+
12
+ def self.extract_from(node)
13
+ if node
14
+ node.inner_html
15
+ end
16
+ end
8
17
  end
9
18
 
10
19
  class << self
@@ -27,15 +36,14 @@ class UrbanAPI
27
36
  req.params['term'] = word
28
37
  req.params['page'] = options[:page].to_i if options.key?(:page)
29
38
  end
30
- definitions_from_html Nokogiri::HTML(resp.body)
39
+ definitions_from_html resp.body
31
40
  end
32
41
 
33
- def definitions_from_html(doc)
42
+ def definitions_from_html(html)
34
43
  defs = []
35
- (doc / "table#entries tr").each do |row|
44
+ (Nokogiri::HTML(html) / "table#entries tr").each do |row|
36
45
  if defn = (row / 'div.definition').first
37
- ex = (row / 'div.example').first
38
- defs << Definition.new(defn.inner_html, ex ? ex.inner_html : nil)
46
+ defs << Definition.create(defn, (row / 'div.example').first)
39
47
  end
40
48
  end
41
49
  defs
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'urban_api'
16
- s.version = '0.1.0'
17
- s.date = '2011-02-15'
16
+ s.version = '0.2.0'
17
+ s.date = '2011-02-20'
18
18
  s.rubyforge_project = 'urban_api'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rick Olson
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-15 00:00:00 -08:00
17
+ date: 2011-02-20 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency