Class: Aranha::Parsers::Base
- Inherits:
-
Object
- Object
- Aranha::Parsers::Base
- Defined in:
- lib/aranha/parsers/base.rb
Direct Known Subclasses
Constant Summary collapse
- LOG_DIR_ENVVAR =
'ARANHA_PARSERS_LOG_DIR'
Instance Attribute Summary collapse
-
#source_address ⇒ Object
readonly
Returns the value of attribute source_address.
Class Method Summary collapse
-
.from_content(content) ⇒ Aranha::Parsers::Base
deprecated
Deprecated.
Use #from_string instead.
- .from_string(string) ⇒ Aranha::Parsers::Base
Instance Method Summary collapse
- #content ⇒ Object
- #content_encoding ⇒ String?
-
#initialize(url) ⇒ Base
constructor
A new instance of Base.
- #source_address_content ⇒ String
Constructor Details
#initialize(url) ⇒ Base
Returns a new instance of Base.
35 36 37 38 |
# File 'lib/aranha/parsers/base.rb', line 35 def initialize(url) @source_address = ::Aranha::Parsers::SourceAddress.new(url) log_content(source_address.serialize, '-source-address') end |
Instance Attribute Details
#source_address ⇒ Object (readonly)
Returns the value of attribute source_address.
33 34 35 |
# File 'lib/aranha/parsers/base.rb', line 33 def source_address @source_address end |
Class Method Details
.from_content(content) ⇒ Aranha::Parsers::Base
Deprecated.
Use #from_string instead.
13 14 15 |
# File 'lib/aranha/parsers/base.rb', line 13 def from_content(content) from_string(content) end |
.from_string(string) ⇒ Aranha::Parsers::Base
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/aranha/parsers/base.rb', line 19 def from_string(string) ::EacRubyUtils::Fs::Temp.on_file do |path| ::File.open(path.to_s, 'w:UTF-8') do |f| f.write string.dup.force_encoding('UTF-8') end r = new(path.to_path) r.content r end end |
Instance Method Details
#content ⇒ Object
42 43 44 |
# File 'lib/aranha/parsers/base.rb', line 42 def content @content ||= log_content(source_address_content) end |
#content_encoding ⇒ String?
47 48 49 |
# File 'lib/aranha/parsers/base.rb', line 47 def content_encoding nil end |
#source_address_content ⇒ String
52 53 54 55 56 |
# File 'lib/aranha/parsers/base.rb', line 52 def source_address_content source_address.content.then do |r| content_encoding.if_present(r) { |v| r.force_encoding(v) } end end |