esaj 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/esaj/query.rb +1 -8
- data/lib/esaj/query_page.rb +8 -10
- data/lib/esaj/result_item.rb +65 -0
- data/lib/esaj/version.rb +1 -1
- metadata +3 -3
- data/lib/esaj/lawsuit.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26bf0d886533a438c54a0a4b6508ff2a06327f707298604aba1d53b386f0155c
|
4
|
+
data.tar.gz: 8811029399cf793a6fececc8f52f8278106bbed358e3708b57fce9d71ae55d30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96a8d372a8498340d6c2989bdf046339b3dd593042bb3309811e4cd1ec1568c4783f2778acaa2bd93dcc2288939b0fc20479839f4d0d96ef56f2c852470beff8
|
7
|
+
data.tar.gz: 2098cc77f209b4a1acbb10d83c8e3f9cdb43e294795e38451fdf8ff7659441f865195b128ba3cc370228e4d1d742b85e5cc9c5d8853b47987aa285a9167eba8b
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/esaj/query.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative 'scraper'
|
2
|
-
require_relative 'lawsuit'
|
3
2
|
|
4
3
|
module Esaj
|
5
4
|
class Query
|
@@ -12,7 +11,7 @@ module Esaj
|
|
12
11
|
|
13
12
|
def perform
|
14
13
|
begin
|
15
|
-
|
14
|
+
scraped_results
|
16
15
|
rescue RemoteError => error
|
17
16
|
{ error: error.message }
|
18
17
|
end
|
@@ -20,12 +19,6 @@ module Esaj
|
|
20
19
|
|
21
20
|
private
|
22
21
|
|
23
|
-
def lawsuits
|
24
|
-
scraped_results.map do |attributes|
|
25
|
-
Lawsuit.new(attributes)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
22
|
def scraped_results
|
30
23
|
Scraper.new(oab_code, forum).results
|
31
24
|
end
|
data/lib/esaj/query_page.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'parser_adapter'
|
2
|
+
require_relative 'result_item'
|
2
3
|
|
3
4
|
module Esaj
|
4
5
|
class QueryPage
|
@@ -9,26 +10,23 @@ module Esaj
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def result_set
|
12
|
-
|
13
|
-
result_set << result_item_for(
|
13
|
+
elements.each_with_object([]) do |element, result_set|
|
14
|
+
result_set << result_item_for(element)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
18
19
|
|
19
|
-
def
|
20
|
-
|
21
|
-
lawsuit_code: result_element.text,
|
22
|
-
lawsuit_details_resource: result_element[:href]
|
23
|
-
}
|
20
|
+
def elements
|
21
|
+
document.css('div[id^="divProcesso"]')
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
27
|
-
|
24
|
+
def result_item_for(element)
|
25
|
+
ResultItem.new(element).attributes
|
28
26
|
end
|
29
27
|
|
30
28
|
def document
|
31
|
-
@
|
29
|
+
@document ||= ParserAdapter.new(url).document
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Esaj
|
2
|
+
class ResultItem
|
3
|
+
attr_reader :element
|
4
|
+
|
5
|
+
def initialize(element)
|
6
|
+
@element = element.children[1]
|
7
|
+
end
|
8
|
+
|
9
|
+
def attributes
|
10
|
+
{
|
11
|
+
code: code,
|
12
|
+
details_resource: details_resource,
|
13
|
+
forum_code: forum_code,
|
14
|
+
forum_name: forum_name,
|
15
|
+
category: category,
|
16
|
+
subject: subject,
|
17
|
+
date: date
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def code
|
24
|
+
element_link.text.strip
|
25
|
+
end
|
26
|
+
|
27
|
+
def details_resource
|
28
|
+
"https://esaj.tjsp.jus.br#{element_link['href']}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def element_link
|
32
|
+
element.at_css('a')
|
33
|
+
end
|
34
|
+
|
35
|
+
def forum_code
|
36
|
+
code[-4..-1]
|
37
|
+
end
|
38
|
+
|
39
|
+
def forum_name
|
40
|
+
receipt_data.last
|
41
|
+
end
|
42
|
+
|
43
|
+
def category
|
44
|
+
striped_text = element.children[2].text.strip
|
45
|
+
striped_text[0, striped_text.size-1]
|
46
|
+
end
|
47
|
+
|
48
|
+
def subject
|
49
|
+
striped_text = element.children[4].text.strip
|
50
|
+
striped_text[1, striped_text.size]
|
51
|
+
end
|
52
|
+
|
53
|
+
def date
|
54
|
+
Date.parse(receipt_data.first[-10..-1])
|
55
|
+
end
|
56
|
+
|
57
|
+
def receipt_data
|
58
|
+
element.children[children_count-2].text.split(' - ').map(&:strip)
|
59
|
+
end
|
60
|
+
|
61
|
+
def children_count
|
62
|
+
element.children.count
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/esaj/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esaj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alberto Rocha
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -115,11 +115,11 @@ files:
|
|
115
115
|
- esaj.gemspec
|
116
116
|
- lib/esaj.rb
|
117
117
|
- lib/esaj/forum.rb
|
118
|
-
- lib/esaj/lawsuit.rb
|
119
118
|
- lib/esaj/metadata.rb
|
120
119
|
- lib/esaj/parser_adapter.rb
|
121
120
|
- lib/esaj/query.rb
|
122
121
|
- lib/esaj/query_page.rb
|
122
|
+
- lib/esaj/result_item.rb
|
123
123
|
- lib/esaj/scraper.rb
|
124
124
|
- lib/esaj/url_builder.rb
|
125
125
|
- lib/esaj/version.rb
|
data/lib/esaj/lawsuit.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Esaj
|
2
|
-
class Lawsuit
|
3
|
-
attr_reader :raw_attributes
|
4
|
-
|
5
|
-
def initialize(raw_attributes)
|
6
|
-
@raw_attributes = raw_attributes
|
7
|
-
end
|
8
|
-
|
9
|
-
def attributes
|
10
|
-
{
|
11
|
-
code: code,
|
12
|
-
details_resource: details_resource
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def code
|
19
|
-
raw_attributes[:lawsuit_code].strip
|
20
|
-
end
|
21
|
-
|
22
|
-
def details_resource
|
23
|
-
"https://esaj.tjsp.jus.br#{raw_attributes[:lawsuit_details_resource]}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|