acts_as_cleo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +20 -3
- data/{LICENSE → LICENSE.txt} +1 -3
- data/README.rdoc +24 -0
- data/Rakefile +54 -2
- data/VERSION +1 -0
- data/acts_as_cleo.gemspec +107 -13
- data/config/cleo.yml +10 -0
- data/lib/acts_as_cleo.rb +17 -105
- data/lib/acts_methods.rb +34 -0
- data/lib/class_methods.rb +4 -0
- data/lib/cleo/reference.rb +5 -0
- data/lib/cleo/result.rb +18 -0
- data/lib/cleo/server.rb +16 -0
- data/lib/cleo.rb +95 -0
- data/lib/common_methods.rb +17 -0
- data/lib/instance_methods.rb +45 -0
- data/test/config/cleo.yml +2 -0
- data/test/data/xml/cleo/element.xml +11 -0
- data/test/data/xml/cleo/elements.xml +90 -0
- data/test/data/xml/cleo/testing_element.xml +11 -0
- data/test/db/connection/sqlite.rb +8 -0
- data/test/db/migrate/001_create_books.rb +13 -0
- data/test/db/migrate/002_create_movies.rb +12 -0
- data/test/db/migrate/003_create_categories.rb +11 -0
- data/test/db/migrate/004_create_electronics.rb +15 -0
- data/test/db/migrate/005_create_authors.rb +12 -0
- data/test/db/migrate/006_create_postings.rb +9 -0
- data/test/db/test.db +0 -0
- data/test/fixtures/authors.yml +9 -0
- data/test/fixtures/books.yml +11 -0
- data/test/fixtures/categories.yml +7 -0
- data/test/fixtures/electronics.yml +39 -0
- data/test/fixtures/movies.yml +9 -0
- data/test/helper.rb +38 -0
- data/test/models/author.rb +7 -0
- data/test/models/book.rb +15 -0
- data/test/models/category.rb +7 -0
- data/test/models/electronic.rb +11 -0
- data/test/models/movie.rb +8 -0
- data/test/test_acts_as_cleo.rb +7 -0
- data/test/unit/test_acts_methods.rb +19 -0
- data/test/unit/test_cleo.rb +60 -0
- data/test/unit/test_result_parser.rb +23 -0
- metadata +161 -13
- data/.gitignore +0 -24
- data/README.md +0 -29
@@ -0,0 +1,90 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<element-list>
|
3
|
+
<element>
|
4
|
+
<term>google</term>
|
5
|
+
<term>inc.</term>
|
6
|
+
<term>goog</term>
|
7
|
+
<id>1063</id>
|
8
|
+
<name>Google Inc. (GOOG)</name>
|
9
|
+
<score>159350.0</score>
|
10
|
+
<timestamp>1331833525493</timestamp>
|
11
|
+
<title>Technology - Computer Software: Programming Data Processing</title>
|
12
|
+
<url>http://www.nasdaq.com/symbol/goog</url>
|
13
|
+
</element>
|
14
|
+
<element>
|
15
|
+
<term>goods</term>
|
16
|
+
<term>corporation</term>
|
17
|
+
<term>big</term>
|
18
|
+
<term>5</term>
|
19
|
+
<term>sporting</term>
|
20
|
+
<term>bgfv</term>
|
21
|
+
<id>303</id>
|
22
|
+
<name>Big 5 Sporting Goods Corporation (BGFV)</name>
|
23
|
+
<score>212.701</score>
|
24
|
+
<timestamp>1331833525461</timestamp>
|
25
|
+
<title>Consumer Services - Other Specialty Stores</title>
|
26
|
+
<url>http://www.nasdaq.com/symbol/bgfv</url>
|
27
|
+
</element>
|
28
|
+
<element>
|
29
|
+
<term>gladstone</term>
|
30
|
+
<term>commercial</term>
|
31
|
+
<term>corporation</term>
|
32
|
+
<term>good</term>
|
33
|
+
<id>1034</id>
|
34
|
+
<name>Gladstone Commercial Corporation (GOOD)</name>
|
35
|
+
<score>194.274</score>
|
36
|
+
<timestamp>1331833525492</timestamp>
|
37
|
+
<title>Consumer Services - Real Estate</title>
|
38
|
+
<url>http://www.nasdaq.com/symbol/good</url>
|
39
|
+
</element>
|
40
|
+
<element>
|
41
|
+
<term>gladstone</term>
|
42
|
+
<term>commercial</term>
|
43
|
+
<term>corporation</term>
|
44
|
+
<term>goodo</term>
|
45
|
+
<id>1035</id>
|
46
|
+
<name>Gladstone Commercial Corporation (GOODO)</name>
|
47
|
+
<score>28.06</score>
|
48
|
+
<timestamp>1331833525492</timestamp>
|
49
|
+
<title>Consumer Services - Real Estate</title>
|
50
|
+
<url>http://www.nasdaq.com/symbol/goodo</url>
|
51
|
+
</element>
|
52
|
+
<element>
|
53
|
+
<term>gladstone</term>
|
54
|
+
<term>commercial</term>
|
55
|
+
<term>corporation</term>
|
56
|
+
<term>goodp</term>
|
57
|
+
<id>1036</id>
|
58
|
+
<name>Gladstone Commercial Corporation (GOODP)</name>
|
59
|
+
<score>24.5</score>
|
60
|
+
<timestamp>1331833525492</timestamp>
|
61
|
+
<title>Consumer Services - Real Estate</title>
|
62
|
+
<url>http://www.nasdaq.com/symbol/goodp</url>
|
63
|
+
</element>
|
64
|
+
<element>
|
65
|
+
<term>inc.</term>
|
66
|
+
<term>real</term>
|
67
|
+
<term>goods</term>
|
68
|
+
<term>solar</term>
|
69
|
+
<term>rsol</term>
|
70
|
+
<id>2052</id>
|
71
|
+
<name>Real Goods Solar Inc. (RSOL)</name>
|
72
|
+
<score>22.5954</score>
|
73
|
+
<timestamp>1331833525534</timestamp>
|
74
|
+
<title>Capital Goods - Building Products</title>
|
75
|
+
<url>http://www.nasdaq.com/symbol/rsol</url>
|
76
|
+
</element>
|
77
|
+
<element>
|
78
|
+
<term>inc.</term>
|
79
|
+
<term>good</term>
|
80
|
+
<term>times</term>
|
81
|
+
<term>restaurants</term>
|
82
|
+
<term>gtim</term>
|
83
|
+
<id>1062</id>
|
84
|
+
<name>Good Times Restaurants Inc. (GTIM)</name>
|
85
|
+
<score>3.43476</score>
|
86
|
+
<timestamp>1331833525493</timestamp>
|
87
|
+
<title>Consumer Services - Restaurants</title>
|
88
|
+
<url>http://www.nasdaq.com/symbol/gtim</url>
|
89
|
+
</element>
|
90
|
+
</element-list>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<element>
|
3
|
+
<term>Wedge</term>
|
4
|
+
<term>Antilles</term>
|
5
|
+
<term>Rogue Squadron</term>
|
6
|
+
<id>4747</id>
|
7
|
+
<name>Wedge Antilles</name>
|
8
|
+
<score>159350.0</score>
|
9
|
+
<title>Rogue Sqadron Member</title>
|
10
|
+
<url>http://starwars.wikia.com/wiki/Wedge_Antilles</url>
|
11
|
+
</element>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateBooks < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :books, :force => true do |t|
|
4
|
+
t.column :category_id, :integer
|
5
|
+
t.column :name, :string
|
6
|
+
t.column :author, :string
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :books
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateElectronics < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :electronics, :force => true do |t|
|
4
|
+
t.column :name, :string
|
5
|
+
t.column :manufacturer, :string
|
6
|
+
t.column :features, :string
|
7
|
+
t.column :category, :string
|
8
|
+
t.column :price, :string
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :electronics
|
14
|
+
end
|
15
|
+
end
|
data/test/db/test.db
ADDED
Binary file
|
@@ -0,0 +1,9 @@
|
|
1
|
+
tom_clancy:
|
2
|
+
id: 1
|
3
|
+
name: Tom Clancy
|
4
|
+
biography: Tom Clancy (born 1947) writes novels of adventure and espionage in the international military-industrial complex that have earned him enormous popularity in the 1980s as a creator of the "techno-thriller" genre.
|
5
|
+
|
6
|
+
stephen_king:
|
7
|
+
id: 2
|
8
|
+
name: Stephen King
|
9
|
+
biography: Stephen King (born 1947) is a prolific and immensely popular author of horror fiction. In his works, King blends elements of the traditional gothic tale with those of the modern psychological thriller, detective, and science fiction genres.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
ipod_video:
|
2
|
+
id: 1
|
3
|
+
name: Apple 60 GB Memory iPod with Video Playback Black
|
4
|
+
manufacturer: Apple Computer Inc.
|
5
|
+
features: iTunes, Podcasts, Audiobooks
|
6
|
+
category: Electronics
|
7
|
+
price: 599.00
|
8
|
+
|
9
|
+
dell_monitor:
|
10
|
+
id: 2
|
11
|
+
name: Dell Widescreen UltraSharp 3007WFP
|
12
|
+
manufacturer: Dell, Inc
|
13
|
+
features: 30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast
|
14
|
+
category: Electronics
|
15
|
+
price: 750.00
|
16
|
+
|
17
|
+
samsung_hd:
|
18
|
+
id: 3
|
19
|
+
name: Samsung SpinPoint P120 SP2514N - hard drive - 250 GB of Memory Storage - ATA-133
|
20
|
+
manufacturer: Samsung Electronics Co. Ltd.
|
21
|
+
features: 7200RPM, 8MB cache, IDE Ultra ATA-133
|
22
|
+
category: Hard Drive
|
23
|
+
price: 319.00
|
24
|
+
|
25
|
+
corsair_ram:
|
26
|
+
id: 4
|
27
|
+
name: CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail
|
28
|
+
manufacturer: Corsair Microsystems Inc.
|
29
|
+
features: CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader
|
30
|
+
category: Memory
|
31
|
+
price: 155.00
|
32
|
+
|
33
|
+
a_data_ram:
|
34
|
+
id: 5
|
35
|
+
name: A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM
|
36
|
+
manufacturer: A-DATA Technology Inc.
|
37
|
+
features: CAS latency 3, 2.7v
|
38
|
+
category: Memory
|
39
|
+
price: 65.79
|
data/test/helper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'rails'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler'
|
7
|
+
require 'active_record'
|
8
|
+
require 'net/http'
|
9
|
+
|
10
|
+
#require acts_as_cleo
|
11
|
+
require File.dirname(__FILE__) + '/../lib/acts_as_cleo'
|
12
|
+
|
13
|
+
begin
|
14
|
+
Bundler.setup(:default, :development)
|
15
|
+
rescue Bundler::BundlerError => e
|
16
|
+
$stderr.puts e.message
|
17
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
18
|
+
exit e.status_code
|
19
|
+
end
|
20
|
+
require 'test/unit'
|
21
|
+
require 'shoulda'
|
22
|
+
|
23
|
+
file_dirname = File.dirname(__FILE__)
|
24
|
+
|
25
|
+
#Load Lib
|
26
|
+
$LOAD_PATH.unshift(File.join(file_dirname, '..', 'lib'))
|
27
|
+
$LOAD_PATH.unshift file_dirname
|
28
|
+
|
29
|
+
#Load sqlilte for testing
|
30
|
+
sqlite = File.join(file_dirname, 'db', 'connection', 'sqlite')
|
31
|
+
require sqlite
|
32
|
+
|
33
|
+
# Load Models
|
34
|
+
models_dir = File.join(file_dirname, 'models')
|
35
|
+
Dir[ models_dir + '/*.rb'].each { |m| require m }
|
36
|
+
|
37
|
+
class Test::Unit::TestCase
|
38
|
+
end
|
data/test/models/book.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Table fields for 'books'
|
2
|
+
# - id
|
3
|
+
# - category_id
|
4
|
+
# - name
|
5
|
+
# - author
|
6
|
+
|
7
|
+
class Book < ActiveRecord::Base
|
8
|
+
belongs_to :category
|
9
|
+
|
10
|
+
acts_as_cleo :terms => %w{name author}, :score => "cleo_score", :name => "name"
|
11
|
+
|
12
|
+
def cleo_score
|
13
|
+
Random.rand(10...47)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
#Literally checking that the acts_as_cleo tag takes args and sets them as expected
|
4
|
+
class TestActsAsMethods < Test::Unit::TestCase
|
5
|
+
|
6
|
+
should "respond to and return as_cleo" do
|
7
|
+
book = Book.new(:name => 'Wedge\'s Life', :author => "Luke Skywalker")
|
8
|
+
assert_equal %w{name author}, book.cleo_config[:terms]
|
9
|
+
assert_equal "name", book.cleo_config[:name]
|
10
|
+
assert_equal "Book", book.cleo_config[:type]
|
11
|
+
end
|
12
|
+
|
13
|
+
should "exclude terms by default" do
|
14
|
+
movie = Movie.create(:name => "A New Hope", :description => "The Best")
|
15
|
+
assert_equal %w{name description}, movie.cleo_config[:terms]
|
16
|
+
assert_equal "id", movie.cleo_config[:score]
|
17
|
+
assert_equal "name", movie.cleo_config[:name]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestCleo < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
file = File.open("#{Dir.pwd}/test/data/xml/cleo/testing_element.xml")
|
6
|
+
contents = file.read
|
7
|
+
@wedge = Cleo::Result.parse(contents, :singluar => true)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "get HTTP Connection" do
|
11
|
+
net = Cleo.net_http
|
12
|
+
assert_not_equal nil, net
|
13
|
+
end
|
14
|
+
|
15
|
+
should "create then destroy Testing Object " do
|
16
|
+
code = Cleo.create(@wedge)
|
17
|
+
assert code
|
18
|
+
|
19
|
+
wa = Cleo.find(@wedge.id)
|
20
|
+
assert_not_nil wa
|
21
|
+
assert_equal @wedge.id, wa.id
|
22
|
+
|
23
|
+
assert Cleo.delete(wa)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "get google results from qery" do
|
27
|
+
r = Cleo.query("goog")
|
28
|
+
assert_not_nil r
|
29
|
+
assert_equal 1, r.count
|
30
|
+
assert_kind_of Array, r
|
31
|
+
end
|
32
|
+
|
33
|
+
should "fetch the same record by id" do
|
34
|
+
r = Cleo.query("goog").first
|
35
|
+
assert_equal r.id.blank?, false
|
36
|
+
|
37
|
+
|
38
|
+
i = Cleo.find(r.id)
|
39
|
+
assert_equal r.timestamp, i.timestamp
|
40
|
+
assert_equal r.id, i.id
|
41
|
+
end
|
42
|
+
|
43
|
+
should "create, update, then destroy, Testing Object" do
|
44
|
+
code = Cleo.create(@wedge)
|
45
|
+
assert code
|
46
|
+
|
47
|
+
wa = Cleo.find(@wedge.id)
|
48
|
+
assert_not_nil wa
|
49
|
+
assert_equal @wedge.id, wa.id
|
50
|
+
|
51
|
+
wa.name = "Luke Skywalker"
|
52
|
+
assert Cleo.update(wa)
|
53
|
+
|
54
|
+
wa_update = Cleo.find(@wedge.id)
|
55
|
+
assert_equal "Luke Skywalker", wa_update.name
|
56
|
+
|
57
|
+
assert Cleo.delete(wa)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "#{File.dirname(File.expand_path(__FILE__))}/../helper"
|
2
|
+
|
3
|
+
class TestResult < Test::Unit::TestCase
|
4
|
+
def test_parser_gets_correct_element
|
5
|
+
file = File.open("#{Dir.pwd}/test/data/xml/cleo/element.xml")
|
6
|
+
contents = file.read
|
7
|
+
cr = Cleo::Result.parse(contents, :singluar => true)
|
8
|
+
|
9
|
+
assert_not_equal cr, nil
|
10
|
+
assert_equal cr.name, "Cleo Inc."
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_parser_gets_many_elements
|
14
|
+
file = File.open("#{Dir.pwd}/test/data/xml/cleo/elements.xml")
|
15
|
+
contents = file.read
|
16
|
+
cr = Cleo::Result.parse(contents)
|
17
|
+
|
18
|
+
assert_equal 7, cr.count
|
19
|
+
assert_match /google/i, cr.first.name
|
20
|
+
assert_equal cr.first.terms, %w{google inc. goog}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|