aranha-parsers 0.5.0 → 0.7.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 291b1da2b4559d999dc1534f79ed111bcfa83f3d6c79e62a049a6eec74443163
|
4
|
+
data.tar.gz: 65f36ed9cee9d1230f9746da5fc6c2e2a3d3c89cf991257ba27aa0451115a9c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e0c6c83985297d6ae1ea39be8471d477982f379c3176c057275f7c758ec3d05d9452110a506e78cb165cff84a639fac774c66b5e5714b606e226f76ad7f604c
|
7
|
+
data.tar.gz: 34b367289ee0c693bbf77f47c6fa000f61791e7a9f0e88e21f5f7fb1bcb2bb6ded0dbd3b0603c069ec0c881e3d021281b3793410025262770bacd03eff2dd306
|
data/lib/aranha/parsers/base.rb
CHANGED
@@ -3,10 +3,26 @@
|
|
3
3
|
require 'open-uri'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'aranha/parsers/source_address'
|
6
|
+
require 'eac_ruby_utils/fs/temp'
|
6
7
|
|
7
8
|
module Aranha
|
8
9
|
module Parsers
|
9
10
|
class Base
|
11
|
+
class << self
|
12
|
+
def from_content(content)
|
13
|
+
::EacRubyUtils::Fs::Temp.on_file do |path|
|
14
|
+
path.write(content)
|
15
|
+
r = new(path.to_path)
|
16
|
+
r.content
|
17
|
+
r
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_content(content)
|
22
|
+
from_content(content).data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
10
26
|
LOG_DIR_ENVVAR = 'ARANHA_PARSERS_LOG_DIR'
|
11
27
|
|
12
28
|
attr_reader :source_address
|
@@ -19,9 +35,11 @@ module Aranha
|
|
19
35
|
delegate :url, to: :source_address
|
20
36
|
|
21
37
|
def content
|
22
|
-
|
23
|
-
|
24
|
-
|
38
|
+
@content ||= begin
|
39
|
+
s = source_address.content
|
40
|
+
log_content(s)
|
41
|
+
s
|
42
|
+
end
|
25
43
|
end
|
26
44
|
|
27
45
|
private
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/core_ext/module/delegation'
|
4
|
-
require 'eac_ruby_utils/
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
5
|
require 'yaml'
|
6
6
|
|
7
7
|
module Aranha
|
8
8
|
module Parsers
|
9
9
|
class SourceAddress
|
10
|
-
|
10
|
+
require_sub __FILE__
|
11
11
|
|
12
12
|
class << self
|
13
13
|
SUBS = [
|
@@ -35,12 +35,8 @@ module Aranha
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
def initialize(source)
|
41
|
-
@sub = self.class.detect_sub(source)
|
42
|
-
end
|
43
|
-
|
38
|
+
enable_simple_cache
|
39
|
+
common_constructor :source
|
44
40
|
delegate :content, :url, to: :sub
|
45
41
|
|
46
42
|
def to_s
|
@@ -50,6 +46,12 @@ module Aranha
|
|
50
46
|
def serialize
|
51
47
|
sub.serialize.strip + "\n"
|
52
48
|
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def sub_uncached
|
53
|
+
self.class.detect_sub(source)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -20,8 +20,8 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
|
|
20
20
|
source_target_fixtures.source_files.each do |source_file|
|
21
21
|
sd = sort_results(source_data(source_file))
|
22
22
|
basename = ::Aranha::Parsers::SourceTargetFixtures.source_target_basename(source_file)
|
23
|
-
target_file = File.expand_path("../#{basename}.target
|
24
|
-
File.write(target_file, sd
|
23
|
+
target_file = File.expand_path("../#{basename}.target#{target_file_extname}", source_file)
|
24
|
+
File.write(target_file, target_content(sd))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
else
|
@@ -46,7 +46,11 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def source_data(source_file)
|
49
|
-
described_class.new(source_file)
|
49
|
+
instance = described_class.new(source_file)
|
50
|
+
return instance.data if instance.respond_to?(:data)
|
51
|
+
|
52
|
+
raise "#{instance} has no \"data\" method. You need to implement \"#{instance}.data\" or " \
|
53
|
+
"\"#{self}.source_data(source_file)\""
|
50
54
|
end
|
51
55
|
|
52
56
|
def fixtures_dir
|
@@ -63,4 +67,12 @@ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable
|
|
63
67
|
def target_data(target_file)
|
64
68
|
::YAML.load_file(target_file)
|
65
69
|
end
|
70
|
+
|
71
|
+
def target_content(data)
|
72
|
+
data.to_yaml
|
73
|
+
end
|
74
|
+
|
75
|
+
def target_file_extname
|
76
|
+
'.yaml'
|
77
|
+
end
|
66
78
|
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.7.2
|
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: 2021-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -112,14 +112,14 @@ dependencies:
|
|
112
112
|
requirements:
|
113
113
|
- - "~>"
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version: '0.
|
115
|
+
version: '0.2'
|
116
116
|
type: :development
|
117
117
|
prerelease: false
|
118
118
|
version_requirements: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
120
|
- - "~>"
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: '0.
|
122
|
+
version: '0.2'
|
123
123
|
description:
|
124
124
|
email:
|
125
125
|
executables: []
|
@@ -165,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
|
-
|
169
|
-
rubygems_version: 2.7.7
|
168
|
+
rubygems_version: 3.0.9
|
170
169
|
signing_key:
|
171
170
|
specification_version: 4
|
172
171
|
summary: Parsers' utilities for Ruby.
|