philologic-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/HISTORY.rdoc +7 -0
- data/README.rdoc +44 -0
- data/Rakefile +15 -0
- data/lib/philologic-client.rb +171 -0
- data/lib/philologic-client/version.rb +7 -0
- data/philologic-client.gemspec +27 -0
- data/test/data/doc_file.html +396 -0
- data/test/data/root_file.html +1851 -0
- data/test/test_philologic_client.rb +132 -0
- metadata +120 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require 'philologic-client'
|
7
|
+
require 'test/unit'
|
8
|
+
require 'mocha'
|
9
|
+
|
10
|
+
class TestPhilologicClient < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@test_dir = File.expand_path( File.dirname(__FILE__) )
|
14
|
+
@data_dir = File.expand_path( File.join( @test_dir, 'data' ) )
|
15
|
+
|
16
|
+
@doc_path = 'doc_file.html'
|
17
|
+
@doc_file = File.join( @data_dir, @doc_path )
|
18
|
+
@endpoint = @data_dir
|
19
|
+
@root_path = 'root_file.html'
|
20
|
+
@root_file = File.join( @data_dir, @root_path )
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# TODO Is there a point to this?
|
25
|
+
def test_initialization
|
26
|
+
blockable = false
|
27
|
+
client = Philologic::Client.new do |client|
|
28
|
+
assert_kind_of Philologic::Client, client
|
29
|
+
blockable = true
|
30
|
+
end
|
31
|
+
assert blockable, 'works as block'
|
32
|
+
assert_kind_of Philologic::Client, client
|
33
|
+
assert_kind_of Philologic::Client, Philologic::Client.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_endpoint_accessor
|
37
|
+
Philologic::Client.new do |client|
|
38
|
+
assert_nil client.endpoint, 'defaults to nil'
|
39
|
+
assert_equal @endpoint, client.endpoint = @endpoint, 'returns value on set'
|
40
|
+
assert_equal @endpoint, client.endpoint, 'returns value on get'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_get_children_without_an_endpoint
|
45
|
+
Philologic::Client.new do |client|
|
46
|
+
assert_raises(RuntimeError) { client.children }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_get_document_without_an_endpoint
|
51
|
+
Philologic::Client.new do |client|
|
52
|
+
assert_raises(RuntimeError) { client.document }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_get_children
|
57
|
+
Philologic::Client.new do |client|
|
58
|
+
children = client.send(:_parse, Nokogiri::HTML( open(@root_file) ) )
|
59
|
+
client.stubs(:_get).with('/').returns(children)
|
60
|
+
assert_equal children, client.children
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_get_document
|
65
|
+
Philologic::Client.new do |client|
|
66
|
+
doc = client.send( :_parse, Nokogiri::HTML( open(@doc_file) ) )
|
67
|
+
client.expects(:_get).with(@doc_path).returns(doc)
|
68
|
+
assert_equal doc, client.document(@doc_path)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_parse_children
|
73
|
+
Philologic::Client.new do |client|
|
74
|
+
client.endpoint = @endpoint
|
75
|
+
children = client.children(@root_path)
|
76
|
+
assert_not_nil children
|
77
|
+
assert_kind_of Array, children
|
78
|
+
assert_equal 1845, children.size
|
79
|
+
children.each do |child|
|
80
|
+
assert_kind_of Philologic::Link, child
|
81
|
+
assert_equal 'philologic_cite', child['class']
|
82
|
+
assert_not_nil child['href']
|
83
|
+
assert_nil child['some random attribute']
|
84
|
+
assert_not_nil child['author']
|
85
|
+
assert_not_nil child['filename']
|
86
|
+
assert_not_nil child['title']
|
87
|
+
assert_raise(NoMethodError) { child.text }
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_equal './1/0/0/0/0/0/0', children.first['href']
|
91
|
+
assert_equal 'Conon, de Béthune, ca. 1160-1219 or 20.', children.first['author']
|
92
|
+
assert_equal 'Les Chansons', children.first['title']
|
93
|
+
assert_equal 'TLF.0.tei', children.first['filename']
|
94
|
+
assert_raise(NoMethodError) { children.first.text }
|
95
|
+
|
96
|
+
assert_equal './1845/0/0/0/0/0/0', children.last['href']
|
97
|
+
assert_equal 'Sartre J.-P.', children.last['author']
|
98
|
+
assert_equal 'Les Mots', children.last['title']
|
99
|
+
assert_equal 'TLF.1879.tei', children.last['filename']
|
100
|
+
assert_raise(NoMethodError) { children.last.text }
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_parse_document
|
106
|
+
Philologic::Client.new do |client|
|
107
|
+
client.endpoint = @endpoint
|
108
|
+
doc = client.document(@doc_path)
|
109
|
+
assert_not_nil doc
|
110
|
+
assert_kind_of Philologic::Document, doc
|
111
|
+
assert_equal 'philologic_object', doc['class']
|
112
|
+
assert_nil doc['some random attribute']
|
113
|
+
assert_kind_of String, doc.text
|
114
|
+
assert_match /^Conon, de Béthune/, doc.text
|
115
|
+
assert_match /verité." $/, doc.text
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_get_document_from_cite
|
120
|
+
Philologic::Client.new do |client|
|
121
|
+
client.endpoint = @endpoint
|
122
|
+
child = client.children(@root_path).first
|
123
|
+
assert_not_nil child
|
124
|
+
assert_kind_of Philologic::Link, child
|
125
|
+
doc = client.send( :_parse, Nokogiri::HTML( open(@doc_file) ) )
|
126
|
+
client.stubs(:_get).with('./1/0/0/0/0/0/0').returns(doc) # TODO Improve
|
127
|
+
assert_equal doc, client.document( child['href'] )
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: philologic-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- blair christensen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70142289748640 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70142289748640
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
requirement: &70142289748200 !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: *70142289748200
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rdoc-readme
|
38
|
+
requirement: &70142289747780 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70142289747780
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: simplecov
|
49
|
+
requirement: &70142289747360 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70142289747360
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: nokogiri
|
60
|
+
requirement: &70142289746940 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70142289746940
|
69
|
+
description: Ruby client for interacting with the Philologic API.
|
70
|
+
email:
|
71
|
+
- blair.christensen@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- HISTORY.rdoc
|
79
|
+
- README.rdoc
|
80
|
+
- Rakefile
|
81
|
+
- lib/philologic-client.rb
|
82
|
+
- lib/philologic-client/version.rb
|
83
|
+
- philologic-client.gemspec
|
84
|
+
- test/data/doc_file.html
|
85
|
+
- test/data/root_file.html
|
86
|
+
- test/test_philologic_client.rb
|
87
|
+
homepage: https://github.com/blairc/philologic-client/
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: -4536869558672298571
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: -4536869558672298571
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project: philologic-client
|
113
|
+
rubygems_version: 1.8.7
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Ruby client for interacting with the Philologic API.
|
117
|
+
test_files:
|
118
|
+
- test/data/doc_file.html
|
119
|
+
- test/data/root_file.html
|
120
|
+
- test/test_philologic_client.rb
|