aranha-parsers 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aranha/parsers.rb +5 -5
- data/lib/aranha/parsers/base.rb +4 -1
- data/lib/aranha/parsers/html.rb +4 -4
- data/lib/aranha/parsers/html/item.rb +1 -0
- data/lib/aranha/parsers/html/item_list.rb +1 -1
- data/lib/aranha/parsers/html/node.rb +4 -2
- data/lib/aranha/parsers/html/node/default.rb +4 -1
- data/lib/aranha/parsers/patches.rb +11 -0
- data/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
- data/lib/aranha/parsers/source_address.rb +6 -6
- data/lib/aranha/parsers/source_address/http_get.rb +2 -0
- data/lib/aranha/parsers/source_target_fixtures.rb +11 -4
- data/lib/aranha/parsers/spec/source_target_fixtures_example.rb +16 -11
- data/lib/aranha/parsers/version.rb +3 -1
- metadata +41 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 990eaaf39db15ed3c74d22039dd4c10ef005a5f46d8e6325087a7517f9795ae9
|
4
|
+
data.tar.gz: 895b5ab2673ff4663576e6a41bfaba3fe96d324df59617e8cfc4f9f116929af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1387956a1035e8984ec724ddff13933b567ca1a8155eec4b7d61c52374d0d9ec398966e146bb46356d57b68cab5926e4ce7a610aed52dac77f5a87eeba5b0d55
|
7
|
+
data.tar.gz: 34f475e75e54677aad15a5650f112acf72a16e50dc4729e8226705181c82d4dc813cc8dbf79493d0a184f4039d947a943cc91bd62e830f797153021194809594
|
data/lib/aranha/parsers.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/require_sub'
|
4
|
+
|
1
5
|
module Aranha
|
2
6
|
module Parsers
|
3
|
-
|
4
|
-
require 'aranha/parsers/html'
|
5
|
-
require 'aranha/parsers/invalid_state_exception'
|
6
|
-
require 'aranha/parsers/source_address'
|
7
|
-
require 'aranha/parsers/version'
|
7
|
+
::EacRubyUtils.require_sub __FILE__
|
8
8
|
end
|
9
9
|
end
|
data/lib/aranha/parsers/base.rb
CHANGED
@@ -30,12 +30,14 @@ module Aranha
|
|
30
30
|
path = log_file(suffix)
|
31
31
|
|
32
32
|
return unless path
|
33
|
+
|
33
34
|
File.open(path, 'wb') { |file| file.write(content) }
|
34
35
|
end
|
35
36
|
|
36
37
|
def log_file(suffix)
|
37
38
|
dir = log_parsers_dir
|
38
39
|
return nil unless dir
|
40
|
+
|
39
41
|
f = ::File.join(dir, "#{self.class.name.parameterize}#{suffix}.log")
|
40
42
|
FileUtils.mkdir_p(File.dirname(f))
|
41
43
|
f
|
@@ -44,6 +46,7 @@ module Aranha
|
|
44
46
|
def log_parsers_dir
|
45
47
|
return ENV[LOG_DIR_ENVVAR] if ENV[LOG_DIR_ENVVAR]
|
46
48
|
return ::Rails.root.join('log', 'parsers') if rails_root_exist?
|
49
|
+
|
47
50
|
nil
|
48
51
|
end
|
49
52
|
|
@@ -51,7 +54,7 @@ module Aranha
|
|
51
54
|
::Rails.root
|
52
55
|
true
|
53
56
|
rescue NameError
|
54
|
-
|
57
|
+
false
|
55
58
|
end
|
56
59
|
end
|
57
60
|
end
|
data/lib/aranha/parsers/html.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/require_sub'
|
4
|
+
|
2
5
|
module Aranha
|
3
6
|
module Parsers
|
4
7
|
module Html
|
5
|
-
|
6
|
-
require 'aranha/parsers/html/item'
|
7
|
-
require 'aranha/parsers/html/item_list'
|
8
|
-
require 'aranha/parsers/html/node'
|
8
|
+
::EacRubyUtils.require_sub __FILE__
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/require_sub'
|
4
|
+
|
2
5
|
module Aranha
|
3
6
|
module Parsers
|
4
7
|
module Html
|
5
8
|
module Node
|
6
|
-
|
7
|
-
require 'aranha/parsers/html/node/default'
|
9
|
+
::EacRubyUtils.require_sub __FILE__
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -19,11 +19,13 @@ module Aranha
|
|
19
19
|
root = node.at_xpath(xpath)
|
20
20
|
if root.blank?
|
21
21
|
return nil unless required
|
22
|
+
|
22
23
|
raise "No node found (Xpath: #{xpath})"
|
23
24
|
end
|
24
25
|
result = string_recursive(root)
|
25
|
-
return result
|
26
|
+
return result if result.present?
|
26
27
|
return nil unless required
|
28
|
+
|
27
29
|
raise "String blank (Xpath: #{xpath})"
|
28
30
|
end
|
29
31
|
|
@@ -109,6 +111,7 @@ module Aranha
|
|
109
111
|
|
110
112
|
def string_recursive(node)
|
111
113
|
return sanitize_string(node.text) if node.is_a?(::Nokogiri::XML::Text)
|
114
|
+
|
112
115
|
s = ''
|
113
116
|
node.children.each do |child|
|
114
117
|
child_s = string_recursive(child)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ofx-parser'
|
4
|
+
|
5
|
+
module Aranha
|
6
|
+
module Parsers
|
7
|
+
module Patches
|
8
|
+
module OfxParser
|
9
|
+
module OfxParser
|
10
|
+
def self.included(base)
|
11
|
+
base.class_eval do
|
12
|
+
class << self
|
13
|
+
prepend ClassMethods
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def build_transaction(transaction)
|
20
|
+
r = super
|
21
|
+
r.currate = (transaction / 'CURRENCY/CURRATE').inner_text
|
22
|
+
r
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Transaction
|
28
|
+
attr_accessor :currate, :cursym
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'eac_ruby_utils/patch'
|
36
|
+
|
37
|
+
::EacRubyUtils.patch(::OfxParser::OfxParser, ::Aranha::Parsers::Patches::OfxParser::OfxParser)
|
38
|
+
::EacRubyUtils.patch(::OfxParser::Transaction, ::Aranha::Parsers::Patches::OfxParser::Transaction)
|
@@ -1,15 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'yaml'
|
4
3
|
require 'active_support/core_ext/module/delegation'
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require 'aranha/parsers/source_address/http_get'
|
8
|
-
require 'aranha/parsers/source_address/file'
|
4
|
+
require 'eac_ruby_utils/require_sub'
|
5
|
+
require 'yaml'
|
9
6
|
|
10
7
|
module Aranha
|
11
8
|
module Parsers
|
12
9
|
class SourceAddress
|
10
|
+
::EacRubyUtils.require_sub __FILE__
|
11
|
+
|
13
12
|
class << self
|
14
13
|
SUBS = [
|
15
14
|
::Aranha::Parsers::SourceAddress::HashHttpGet,
|
@@ -20,6 +19,7 @@ module Aranha
|
|
20
19
|
|
21
20
|
def detect_sub(source)
|
22
21
|
return source.sub if source.is_a?(self)
|
22
|
+
|
23
23
|
SUBS.each do |sub|
|
24
24
|
return sub.new(source) if sub.valid_source?(source)
|
25
25
|
end
|
@@ -27,7 +27,7 @@ module Aranha
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def deserialize(string)
|
30
|
-
new(string =~ %r{\A[a-z]+://} ? string.strip : ::YAML.load(string))
|
30
|
+
new(string =~ %r{\A[a-z]+://} ? string.strip : ::YAML.load(string)) # rubocop:disable Security/YAMLLoad
|
31
31
|
end
|
32
32
|
|
33
33
|
def from_file(path)
|
@@ -33,8 +33,10 @@ module Aranha
|
|
33
33
|
|
34
34
|
def content
|
35
35
|
c = ::Curl::Easy.new(url)
|
36
|
+
c.follow_location = true
|
36
37
|
raise "Curl perform failed (URL: #{url})" unless c.perform
|
37
38
|
return c.body_str if c.status.to_i == 200
|
39
|
+
|
38
40
|
raise "Get #{url} returned #{c.status.to_i}"
|
39
41
|
end
|
40
42
|
|
@@ -1,9 +1,7 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'active_support/core_ext/object'
|
5
4
|
require 'active_support/core_ext/string'
|
6
|
-
require 'yaml'
|
7
5
|
|
8
6
|
module Aranha
|
9
7
|
module Parsers
|
@@ -37,6 +35,14 @@ module Aranha
|
|
37
35
|
r
|
38
36
|
end
|
39
37
|
|
38
|
+
def target_files
|
39
|
+
r = []
|
40
|
+
source_target_files.each do |st|
|
41
|
+
r << st.target if st.target
|
42
|
+
end
|
43
|
+
r
|
44
|
+
end
|
45
|
+
|
40
46
|
def target_file(basename)
|
41
47
|
fixture_file(basename, 'target')
|
42
48
|
end
|
@@ -50,7 +56,7 @@ module Aranha
|
|
50
56
|
def fixture_file(basename, suffix)
|
51
57
|
prefix = "#{basename}.#{suffix}"
|
52
58
|
Dir.foreach(fixtures_directory) do |item|
|
53
|
-
next if
|
59
|
+
next if %w[. ..].include?(item)
|
54
60
|
return File.expand_path(item, fixtures_directory) if item.starts_with?(prefix)
|
55
61
|
end
|
56
62
|
nil
|
@@ -59,7 +65,8 @@ module Aranha
|
|
59
65
|
def sources_targets_basenames
|
60
66
|
basenames = Set.new
|
61
67
|
Dir.foreach(fixtures_directory) do |item|
|
62
|
-
next if
|
68
|
+
next if %w[. ..].include?(item)
|
69
|
+
|
63
70
|
b = self.class.source_target_basename(item)
|
64
71
|
basenames << b if b.present?
|
65
72
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'aranha/parsers/source_target_fixtures'
|
4
|
+
require 'yaml'
|
4
5
|
|
5
6
|
RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable Metrics/BlockLength
|
6
7
|
let(:spec_file) { spec_file }
|
@@ -9,13 +10,13 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
|
|
9
10
|
expect(::File.directory?(fixtures_dir)).to be true
|
10
11
|
end
|
11
12
|
|
12
|
-
context '
|
13
|
-
it '
|
14
|
-
expect(source_target_fixtures.source_target_files.count).to be > 0
|
13
|
+
context 'with fixtures directory' do
|
14
|
+
it 'has at least one file' do
|
15
|
+
expect(source_target_fixtures.source_target_files.count).to be > 0 # rubocop:disable Style/NumericPredicate
|
15
16
|
end
|
16
17
|
|
17
18
|
if ENV['WRITE_TARGET_FIXTURES']
|
18
|
-
it '
|
19
|
+
it 'writes target data for all files' do
|
19
20
|
source_target_fixtures.source_files.each do |source_file|
|
20
21
|
sd = sort_results(source_data(source_file))
|
21
22
|
basename = ::Aranha::Parsers::SourceTargetFixtures.source_target_basename(source_file)
|
@@ -24,11 +25,11 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
else
|
27
|
-
it '
|
28
|
+
it 'parses data for all files' do
|
28
29
|
source_target_fixtures.source_target_files.each do |st|
|
29
30
|
assert_source_target_complete(st)
|
30
31
|
sd = source_data(st.source)
|
31
|
-
td =
|
32
|
+
td = target_data(st.target)
|
32
33
|
expect(sort_results(sd)).to eq(sort_results(td))
|
33
34
|
end
|
34
35
|
end
|
@@ -39,9 +40,9 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
|
|
39
40
|
@source_target_fixtures ||= ::Aranha::Parsers::SourceTargetFixtures.new(fixtures_dir)
|
40
41
|
end
|
41
42
|
|
42
|
-
def assert_source_target_complete(
|
43
|
-
expect(
|
44
|
-
expect(
|
43
|
+
def assert_source_target_complete(source_target)
|
44
|
+
expect(source_target.source).to(be_truthy, "Source not found (Target: #{source_target.target})")
|
45
|
+
expect(source_target.target).to(be_truthy, "Target not found (Source: #{source_target.source})")
|
45
46
|
end
|
46
47
|
|
47
48
|
def source_data(source_file)
|
@@ -55,7 +56,11 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
|
|
55
56
|
)
|
56
57
|
end
|
57
58
|
|
58
|
-
def sort_results(
|
59
|
-
|
59
|
+
def sort_results(results)
|
60
|
+
results
|
61
|
+
end
|
62
|
+
|
63
|
+
def target_data(target_file)
|
64
|
+
::YAML.load_file(target_file)
|
60
65
|
end
|
61
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aranha-parsers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,6 +52,26 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.9.10
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: eac_ruby_utils
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.33'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.33.1
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0.33'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.33.1
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
76
|
name: httpclient
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,19 +93,33 @@ dependencies:
|
|
73
93
|
- !ruby/object:Gem::Version
|
74
94
|
version: 2.8.3
|
75
95
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
96
|
+
name: ofx-parser
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.1.0
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 1.1.0
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: eac_ruby_gem_support
|
77
111
|
requirement: !ruby/object:Gem::Requirement
|
78
112
|
requirements:
|
79
113
|
- - "~>"
|
80
114
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
115
|
+
version: '0.1'
|
82
116
|
type: :development
|
83
117
|
prerelease: false
|
84
118
|
version_requirements: !ruby/object:Gem::Requirement
|
85
119
|
requirements:
|
86
120
|
- - "~>"
|
87
121
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
122
|
+
version: '0.1'
|
89
123
|
description:
|
90
124
|
email:
|
91
125
|
executables: []
|
@@ -103,6 +137,8 @@ files:
|
|
103
137
|
- lib/aranha/parsers/html/node/base.rb
|
104
138
|
- lib/aranha/parsers/html/node/default.rb
|
105
139
|
- lib/aranha/parsers/invalid_state_exception.rb
|
140
|
+
- lib/aranha/parsers/patches.rb
|
141
|
+
- lib/aranha/parsers/patches/ofx_parser.rb
|
106
142
|
- lib/aranha/parsers/source_address.rb
|
107
143
|
- lib/aranha/parsers/source_address/file.rb
|
108
144
|
- lib/aranha/parsers/source_address/hash_http_get.rb
|