Class: Aranha::Parsers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aranha/parsers/base.rb

Direct Known Subclasses

Html::Base, Json::Base

Constant Summary collapse

LOG_DIR_ENVVAR =
'ARANHA_PARSERS_LOG_DIR'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Base

Returns a new instance of Base.



32
33
34
35
# File 'lib/aranha/parsers/base.rb', line 32

def initialize(url)
  @source_address = ::Aranha::Parsers::SourceAddress.new(url)
  log_content(source_address.serialize, '-source-address')
end

Instance Attribute Details

#source_addressObject (readonly)

Returns the value of attribute source_address.



30
31
32
# File 'lib/aranha/parsers/base.rb', line 30

def source_address
  @source_address
end

Class Method Details

.from_content(content) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/aranha/parsers/base.rb', line 12

def from_content(content)
  ::EacRubyUtils::Fs::Temp.on_file do |path|
    ::File.open(path.to_s, 'w:UTF-8') do |f|
      f.write content.dup.force_encoding('UTF-8')
    end
    r = new(path.to_path)
    r.content
    r
  end
end

.parse_content(content) ⇒ Object



23
24
25
# File 'lib/aranha/parsers/base.rb', line 23

def parse_content(content)
  from_content(content).data
end

Instance Method Details

#contentString

Returns:

  • (String)


44
45
46
# File 'lib/aranha/parsers/base.rb', line 44

def content
  @content ||= log_content(source_address_content)
end