ehbrs-tools 0.16.0 → 0.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs/runner/videos/probe.rb +3 -3
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
- data/lib/ehbrs/videos/file.rb +4 -8
- data/lib/ehbrs/videos/track.rb +5 -13
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +3 -1
- data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +3 -1
- data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +4 -2
- data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +3 -1
- data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +0 -13
- data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +10 -10
- data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
- data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
- data/vendor/aranha-parsers/Gemfile +5 -0
- data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
- data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
- data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
- data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
- data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
- data/vendor/eac_cli/eac_cli.gemspec +1 -1
- data/vendor/eac_cli/lib/eac_cli/definition.rb +36 -31
- data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
- data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +15 -2
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
- data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
- data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
- data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +12 -4
- data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +18 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +6 -1
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +10 -0
- data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +17 -5
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +29 -1
- data/vendor/eac_docker/lib/eac_docker/container.rb +24 -0
- data/vendor/eac_docker/lib/eac_docker/images/coded.rb +39 -0
- data/vendor/eac_docker/lib/eac_docker/images/templatized.rb +26 -0
- data/vendor/eac_docker/lib/eac_docker/registry.rb +17 -0
- data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +12 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +1 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +17 -0
- data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +1 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +7 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
- metadata +92 -13
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +0 -127
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -38
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -77
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'aranha/parsers/base'
|
5
|
+
require 'aranha/parsers/html/node/default'
|
6
|
+
|
7
|
+
module Aranha
|
8
|
+
module Parsers
|
9
|
+
module Html
|
10
|
+
class Base < ::Aranha::Parsers::Base
|
11
|
+
class << self
|
12
|
+
def fields
|
13
|
+
@fields ||= []
|
14
|
+
@fields.dup
|
15
|
+
end
|
16
|
+
|
17
|
+
def field(name, type, xpath)
|
18
|
+
@fields ||= []
|
19
|
+
@fields << Field.new(name, type, xpath)
|
20
|
+
end
|
21
|
+
|
22
|
+
Field = Struct.new(:name, :type, :xpath)
|
23
|
+
end
|
24
|
+
|
25
|
+
def nokogiri
|
26
|
+
@nokogiri ||= Nokogiri::HTML(content, &:noblanks)
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def node_parser_class
|
32
|
+
::Aranha::Parsers::Html::Node::Default
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def node_parser
|
38
|
+
@node_parser ||= node_parser_class.new(fields)
|
39
|
+
end
|
40
|
+
|
41
|
+
def fields
|
42
|
+
self.class.fields.map { |f| [f.name, f.type, f.xpath] }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/html/base'
|
4
|
+
|
5
|
+
module Aranha
|
6
|
+
module Parsers
|
7
|
+
module Html
|
8
|
+
class Item < Base
|
9
|
+
def data
|
10
|
+
@data ||= node_parser.parse(item_node)
|
11
|
+
end
|
12
|
+
|
13
|
+
def item_node
|
14
|
+
@item_node ||= begin
|
15
|
+
r = item_xpath ? nokogiri.at_xpath(item_xpath) : nokogiri
|
16
|
+
raise "Item node not found (Item xpath: #{item_xpath})" unless r
|
17
|
+
|
18
|
+
r
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/html/base'
|
4
|
+
|
5
|
+
module Aranha
|
6
|
+
module Parsers
|
7
|
+
module Html
|
8
|
+
class ItemList < Base
|
9
|
+
def data
|
10
|
+
items_data
|
11
|
+
end
|
12
|
+
|
13
|
+
def items_data
|
14
|
+
count = 0
|
15
|
+
@data ||= nokogiri.xpath(items_xpath).map do |m|
|
16
|
+
count += 1
|
17
|
+
node_parser.parse(m)
|
18
|
+
end
|
19
|
+
rescue StandardError => e
|
20
|
+
raise StandardError, "#{e.message} (Count: #{count})"
|
21
|
+
end
|
22
|
+
|
23
|
+
def items_xpath
|
24
|
+
raise "Class #{self.class} has no method \"#{__method__}\". Implement it"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aranha
|
4
|
+
module Parsers
|
5
|
+
module Html
|
6
|
+
module Node
|
7
|
+
class Base
|
8
|
+
attr_reader :fields
|
9
|
+
|
10
|
+
def initialize(fields)
|
11
|
+
@fields = fields
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse(node)
|
15
|
+
fields.map do |f|
|
16
|
+
begin
|
17
|
+
[f[0], parse_field(node, f[2], f[1])]
|
18
|
+
rescue StandardError => e
|
19
|
+
raise StandardError, "#{e.message}\nFields: #{f}"
|
20
|
+
end
|
21
|
+
end.to_h
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def parse_field(node, xpath, parser_method)
|
27
|
+
value_method = "#{parser_method}_value"
|
28
|
+
return send(value_method, node, xpath) if respond_to?(value_method)
|
29
|
+
|
30
|
+
raise "Method \"#{value_method}\" not found in #{self.class}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/html/node/base'
|
4
|
+
|
5
|
+
module Aranha
|
6
|
+
module Parsers
|
7
|
+
module Html
|
8
|
+
module Node
|
9
|
+
class Default < ::Aranha::Parsers::Html::Node::Base
|
10
|
+
def string_value(node, xpath)
|
11
|
+
if node.at_xpath(xpath)
|
12
|
+
sanitize_string(node.at_xpath(xpath).text)
|
13
|
+
else
|
14
|
+
''
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def string_recursive_value(node, xpath, required = true)
|
19
|
+
root = node.at_xpath(xpath)
|
20
|
+
if root.blank?
|
21
|
+
return nil unless required
|
22
|
+
|
23
|
+
raise "No node found (Xpath: #{xpath})"
|
24
|
+
end
|
25
|
+
result = string_recursive(root)
|
26
|
+
return result if result.present?
|
27
|
+
return nil unless required
|
28
|
+
|
29
|
+
raise "String blank (Xpath: #{xpath})"
|
30
|
+
end
|
31
|
+
|
32
|
+
def string_recursive_optional_value(node, xpath)
|
33
|
+
string_recursive_value(node, xpath, false)
|
34
|
+
end
|
35
|
+
|
36
|
+
def quoted_value(node, xpath)
|
37
|
+
s = string_value(node, xpath)
|
38
|
+
return '' unless s
|
39
|
+
|
40
|
+
m = /\"([^\"]+)\"/.match(s)
|
41
|
+
return m[1] if m
|
42
|
+
|
43
|
+
''
|
44
|
+
end
|
45
|
+
|
46
|
+
def integer_value(node, xpath)
|
47
|
+
r = string_value(node, xpath)
|
48
|
+
return nil if r.blank?
|
49
|
+
|
50
|
+
m = /\d+/.match(r)
|
51
|
+
raise "Integer not found in \"#{r}\"" unless m
|
52
|
+
|
53
|
+
m[0].to_i
|
54
|
+
end
|
55
|
+
|
56
|
+
def integer_optional_value(node, xpath)
|
57
|
+
r = string_value(node, xpath)
|
58
|
+
m = /\d+/.match(r)
|
59
|
+
m ? m[0].to_i : nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def float_value(node, xpath)
|
63
|
+
parse_float(node, xpath, true)
|
64
|
+
end
|
65
|
+
|
66
|
+
def float_optional_value(node, xpath)
|
67
|
+
parse_float(node, xpath, false)
|
68
|
+
end
|
69
|
+
|
70
|
+
def array_value(node, xpath)
|
71
|
+
r = node.xpath(xpath).map { |n| n.text.strip }
|
72
|
+
r.join('|')
|
73
|
+
end
|
74
|
+
|
75
|
+
def join_value(node, xpath)
|
76
|
+
m = ''
|
77
|
+
node.xpath(xpath).each do |n|
|
78
|
+
m << n.text.strip
|
79
|
+
end
|
80
|
+
m
|
81
|
+
end
|
82
|
+
|
83
|
+
def duration_value(node, xpath)
|
84
|
+
m = /(\d+) m/.match(join_value(node, xpath))
|
85
|
+
m ? m[1].to_i : nil
|
86
|
+
end
|
87
|
+
|
88
|
+
def regxep(node, xpath, pattern)
|
89
|
+
s = string_value(node, xpath)
|
90
|
+
m = pattern.match(s)
|
91
|
+
return m if m
|
92
|
+
|
93
|
+
raise "Pattern \"#{pattern}\" not found in string \"#{s}\""
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def parse_float(node, xpath, required)
|
99
|
+
s = string_value(node, xpath)
|
100
|
+
m = /\d+(?:[\.\,](\d+))?/.match(s)
|
101
|
+
if m
|
102
|
+
m[0].delete('.').tr(',', '.').to_f
|
103
|
+
elsif required
|
104
|
+
raise "Float value not found in \"#{s}\""
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def sanitize_string(obj)
|
109
|
+
obj.to_s.tr("\u00A0", ' ').strip
|
110
|
+
end
|
111
|
+
|
112
|
+
def string_recursive(node)
|
113
|
+
return sanitize_string(node.text) if node.is_a?(::Nokogiri::XML::Text)
|
114
|
+
|
115
|
+
s = ''
|
116
|
+
node.children.each do |child|
|
117
|
+
child_s = string_recursive(child)
|
118
|
+
s += ' ' + child_s if child_s.present?
|
119
|
+
end
|
120
|
+
sanitize_string(s)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -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)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
require 'eac_ruby_utils/require_sub'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module Aranha
|
8
|
+
module Parsers
|
9
|
+
class SourceAddress
|
10
|
+
::EacRubyUtils.require_sub __FILE__
|
11
|
+
|
12
|
+
class << self
|
13
|
+
SUBS = [
|
14
|
+
::Aranha::Parsers::SourceAddress::HashHttpGet,
|
15
|
+
::Aranha::Parsers::SourceAddress::HashHttpPost,
|
16
|
+
::Aranha::Parsers::SourceAddress::HttpGet,
|
17
|
+
::Aranha::Parsers::SourceAddress::File
|
18
|
+
].freeze
|
19
|
+
|
20
|
+
def detect_sub(source)
|
21
|
+
return source.sub if source.is_a?(self)
|
22
|
+
|
23
|
+
SUBS.each do |sub|
|
24
|
+
return sub.new(source) if sub.valid_source?(source)
|
25
|
+
end
|
26
|
+
raise "No content fetcher found for source \"#{source}\""
|
27
|
+
end
|
28
|
+
|
29
|
+
def deserialize(string)
|
30
|
+
new(string =~ %r{\A[a-z]+://} ? string.strip : ::YAML.load(string)) # rubocop:disable Security/YAMLLoad
|
31
|
+
end
|
32
|
+
|
33
|
+
def from_file(path)
|
34
|
+
deserialize(::File.read(path))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_reader :sub
|
39
|
+
|
40
|
+
def initialize(source)
|
41
|
+
@sub = self.class.detect_sub(source)
|
42
|
+
end
|
43
|
+
|
44
|
+
delegate :content, :url, to: :sub
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
sub.url
|
48
|
+
end
|
49
|
+
|
50
|
+
def serialize
|
51
|
+
sub.serialize.strip + "\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/source_address/http_get'
|
4
|
+
|
5
|
+
module Aranha
|
6
|
+
module Parsers
|
7
|
+
class SourceAddress
|
8
|
+
class File < ::Aranha::Parsers::SourceAddress::HttpGet
|
9
|
+
SCHEME = 'file://'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def valid_source?(source)
|
13
|
+
source.to_s.start_with?(SCHEME + '/', '/')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(source)
|
18
|
+
super source.to_s.gsub(/\A#{Regexp.quote(SCHEME)}/, '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def url
|
22
|
+
"#{SCHEME}#{source}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def content
|
26
|
+
::File.open(source, &:read)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/source_address/hash_http_post'
|
4
|
+
|
5
|
+
module Aranha
|
6
|
+
module Parsers
|
7
|
+
class SourceAddress
|
8
|
+
class HashHttpGet < ::Aranha::Parsers::SourceAddress::HashHttpPost
|
9
|
+
class << self
|
10
|
+
def valid_source?(source)
|
11
|
+
source.is_a?(::Hash) &&
|
12
|
+
source.with_indifferent_access[:method].to_s.downcase.strip == 'get'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def content
|
17
|
+
HTTPClient.new.get_content(
|
18
|
+
source[:url],
|
19
|
+
source[:params]
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|