philologic-client 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.rdoc +5 -0
- data/README.rdoc +8 -5
- data/lib/philologic-client/version.rb +1 -1
- data/lib/philologic-client.rb +25 -10
- data/test/test_philologic_client.rb +25 -1
- metadata +14 -14
data/HISTORY.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
# Get document
|
15
15
|
first = client.children.first
|
16
|
-
doc =
|
16
|
+
doc = first.document
|
17
17
|
txt = doc.text
|
18
18
|
|
19
19
|
# Search (currently only limited support)
|
@@ -21,6 +21,10 @@
|
|
21
21
|
puts [ child['href'], child['author'], child['title'] ].join("\t")
|
22
22
|
end
|
23
23
|
|
24
|
+
# Get/Set encoding
|
25
|
+
encoding = client.encoding
|
26
|
+
client.encoding = 'utf-8' # Default
|
27
|
+
|
24
28
|
# Get/Set endpoint
|
25
29
|
endpoint = client.endpoint
|
26
30
|
client.endpoint = 'http://philologic.example.org'
|
@@ -42,11 +46,10 @@ https://github.com/blairc/philologic-client/
|
|
42
46
|
|
43
47
|
== To Do
|
44
48
|
|
45
|
-
*
|
49
|
+
* Expand search support
|
50
|
+
* Switch to MiniTest::Mock?
|
46
51
|
* Add +children+ to Philologic::Document
|
47
52
|
* Add +parent+ to Philologic::Document
|
48
|
-
*
|
49
|
-
* Expand search support
|
50
|
-
* Unifiy Philologic::Link and Philologic::Document
|
53
|
+
* Unify Philologic::Link and Philologic::Document
|
51
54
|
* Build +RDoc+
|
52
55
|
|
data/lib/philologic-client.rb
CHANGED
@@ -21,7 +21,7 @@ require 'open-uri'
|
|
21
21
|
#
|
22
22
|
# # Get document
|
23
23
|
# first = client.children.first
|
24
|
-
# doc =
|
24
|
+
# doc = first.document
|
25
25
|
# txt = doc.text
|
26
26
|
#
|
27
27
|
# # Search (currently only limited support)
|
@@ -29,6 +29,10 @@ require 'open-uri'
|
|
29
29
|
# puts [ child['href'], child['author'], child['title'] ].join("\t")
|
30
30
|
# end
|
31
31
|
#
|
32
|
+
# # Get/Set encoding
|
33
|
+
# encoding = client.encoding
|
34
|
+
# client.encoding = 'utf-8' # Default
|
35
|
+
#
|
32
36
|
# # Get/Set endpoint
|
33
37
|
# endpoint = client.endpoint
|
34
38
|
# client.endpoint = 'http://philologic.example.org'
|
@@ -50,12 +54,11 @@ require 'open-uri'
|
|
50
54
|
#
|
51
55
|
# == To Do
|
52
56
|
#
|
53
|
-
# *
|
57
|
+
# * Expand search support
|
58
|
+
# * Switch to MiniTest::Mock?
|
54
59
|
# * Add +children+ to Philologic::Document
|
55
60
|
# * Add +parent+ to Philologic::Document
|
56
|
-
# *
|
57
|
-
# * Expand search support
|
58
|
-
# * Unifiy Philologic::Link and Philologic::Document
|
61
|
+
# * Unify Philologic::Link and Philologic::Document
|
59
62
|
# * Build +RDoc+
|
60
63
|
#
|
61
64
|
module Philologic
|
@@ -65,11 +68,15 @@ module Philologic
|
|
65
68
|
#
|
66
69
|
class Client
|
67
70
|
|
71
|
+
#
|
72
|
+
# Get/Set +encoding+
|
73
|
+
#
|
74
|
+
attr_accessor :encoding
|
75
|
+
|
68
76
|
#
|
69
77
|
# Get/Set +endpoint+
|
70
78
|
#
|
71
79
|
attr_accessor :endpoint
|
72
|
-
|
73
80
|
|
74
81
|
#
|
75
82
|
# Initialize Philologic::Client
|
@@ -78,6 +85,7 @@ module Philologic
|
|
78
85
|
# +endpoint+:: Philologic endpoint (defaults to +nil+)
|
79
86
|
#
|
80
87
|
def initialize( endpoint = nil )
|
88
|
+
@encoding = 'utf-8'
|
81
89
|
@endpoint = endpoint
|
82
90
|
yield self if block_given?
|
83
91
|
self
|
@@ -129,20 +137,20 @@ module Philologic
|
|
129
137
|
def _get(path)
|
130
138
|
raise('no endpoint specified') if @endpoint.nil?
|
131
139
|
uri = "#{ @endpoint }#{ @endpoint =~ /\/$/ || '/' }#{ path }"
|
132
|
-
_parse( Nokogiri::HTML( open(uri).read, nil,
|
140
|
+
_parse( Nokogiri::HTML( open(uri).read, nil, @encoding ) )
|
133
141
|
end
|
134
142
|
|
135
143
|
def _parse(doc)
|
136
144
|
if !doc.css('div.philologic_cite_list').first.nil?
|
137
145
|
children = []
|
138
146
|
doc.css('div.philologic_cite_list').css('a.philologic_cite').each do |cite|
|
139
|
-
children << Philologic::Link.new(cite) # TODO Why not a select?
|
147
|
+
children << Philologic::Link.new(self, cite) # TODO Why not a select?
|
140
148
|
end
|
141
149
|
return children
|
142
150
|
elsif !doc.css('div.philologic_concordance').first.nil?
|
143
151
|
results = []
|
144
152
|
doc.css('div.philologic_concordance').css('a.philologic_cite').each do |cite|
|
145
|
-
results << Philologic::Link.new(cite) # TODO Why not a select?
|
153
|
+
results << Philologic::Link.new(self, cite) # TODO Why not a select?
|
146
154
|
end
|
147
155
|
return results
|
148
156
|
elsif !doc.css('div.philologic_object').first.nil?
|
@@ -191,7 +199,8 @@ module Philologic
|
|
191
199
|
#
|
192
200
|
class Link
|
193
201
|
|
194
|
-
def initialize(document)
|
202
|
+
def initialize(client, document)
|
203
|
+
@client = client
|
195
204
|
@doc = document
|
196
205
|
# TODO Prefer lazy initialization?
|
197
206
|
@properties = {}
|
@@ -207,6 +216,12 @@ module Philologic
|
|
207
216
|
@doc.attributes.key?(key) ? @doc.attributes[key].value : @properties[key]
|
208
217
|
end
|
209
218
|
|
219
|
+
#
|
220
|
+
# Returns Philologic::Document referenced by this Philologic::Link object.
|
221
|
+
def document
|
222
|
+
@client.document( self['href'] )
|
223
|
+
end
|
224
|
+
|
210
225
|
end # class Philologic::Link
|
211
226
|
|
212
227
|
|
@@ -50,6 +50,18 @@ class TestPhilologicClient < Test::Unit::TestCase
|
|
50
50
|
assert_equal @endpoint, client.endpoint
|
51
51
|
end
|
52
52
|
|
53
|
+
def test_encoding_accessor
|
54
|
+
Philologic::Client.new do |client|
|
55
|
+
assert_equal 'utf-8', client.encoding
|
56
|
+
assert_equal 'foo', client.encoding = 'foo'
|
57
|
+
assert_equal 'foo', client.encoding
|
58
|
+
#
|
59
|
+
# assert_nil client.endpoint, 'defaults to nil'
|
60
|
+
# assert_equal @endpoint, client.endpoint = @endpoint, 'returns value on set'
|
61
|
+
# assert_equal @endpoint, client.endpoint, 'returns value on get'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
53
65
|
def test_endpoint_accessor
|
54
66
|
Philologic::Client.new do |client|
|
55
67
|
assert_nil client.endpoint, 'defaults to nil'
|
@@ -133,7 +145,7 @@ class TestPhilologicClient < Test::Unit::TestCase
|
|
133
145
|
end
|
134
146
|
end
|
135
147
|
|
136
|
-
def
|
148
|
+
def test_get_document_from_cite_through_client
|
137
149
|
Philologic::Client.new do |client|
|
138
150
|
client.endpoint = @endpoint
|
139
151
|
child = client.children(@root_path).first
|
@@ -145,6 +157,18 @@ class TestPhilologicClient < Test::Unit::TestCase
|
|
145
157
|
end
|
146
158
|
end
|
147
159
|
|
160
|
+
def test_get_document_from_cite
|
161
|
+
Philologic::Client.new do |client|
|
162
|
+
client.endpoint = @endpoint
|
163
|
+
child = client.children(@root_path).first
|
164
|
+
assert_not_nil child
|
165
|
+
assert_kind_of Philologic::Link, child
|
166
|
+
doc = client.send( :_parse, Nokogiri::HTML( open(@doc_file) ) )
|
167
|
+
client.stubs(:_get).with('./1/0/0/0/0/0/0').returns(doc) # TODO Improve
|
168
|
+
assert_equal doc, child.document
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
148
172
|
def test_nil_search
|
149
173
|
Philologic::Client.new(@endpoint) do |client|
|
150
174
|
assert_raise(RuntimeError, 'no query specified') { client.search(nil) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: philologic-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-03 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70270934047440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70270934047440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mocha
|
27
|
-
requirement: &
|
27
|
+
requirement: &70270934047000 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70270934047000
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rdoc-readme
|
38
|
-
requirement: &
|
38
|
+
requirement: &70270934046580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70270934046580
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: simplecov
|
49
|
-
requirement: &
|
49
|
+
requirement: &70270934046160 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70270934046160
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: nokogiri
|
60
|
-
requirement: &
|
60
|
+
requirement: &70270934045740 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70270934045740
|
69
69
|
description: Ruby client for interacting with the Philologic API.
|
70
70
|
email:
|
71
71
|
- blair.christensen@gmail.com
|
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
segments:
|
101
101
|
- 0
|
102
|
-
hash: -
|
102
|
+
hash: -2626252476221214395
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
none: false
|
105
105
|
requirements:
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
segments:
|
110
110
|
- 0
|
111
|
-
hash: -
|
111
|
+
hash: -2626252476221214395
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project: philologic-client
|
114
114
|
rubygems_version: 1.8.7
|