Class: Crabfarm::BaseReducer

Inherits:
Delegator
  • Object
show all
Includes:
Assertion::Fields, Base, Live::Interactable
Defined in:
lib/crabfarm/base_reducer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Live::Interactable

#highlight, included

Methods included from Assertion::Fields

#attributes=, #field_hash, included, #mock, #reset_fields

Methods included from Assertion::Context

#assert

Methods included from Base

#debugger

Constructor Details

#initialize(_target, _params) ⇒ BaseReducer



30
31
32
33
34
35
36
37
38
# File 'lib/crabfarm/base_reducer.rb', line 30

def initialize(_target, _params)
  reset_fields

  @raw_document = parser.preprocess_parsing_target _target
  @document = parser.parse @raw_document
  @params = _params

  super @document
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



11
12
13
# File 'lib/crabfarm/base_reducer.rb', line 11

def document
  @document
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/crabfarm/base_reducer.rb', line 11

def params
  @params
end

#raw_documentObject (readonly)

Returns the value of attribute raw_document.



11
12
13
# File 'lib/crabfarm/base_reducer.rb', line 11

def raw_document
  @raw_document
end

Class Method Details

.parserObject



17
18
19
# File 'lib/crabfarm/base_reducer.rb', line 17

def self.parser
  @parser ||= Strategies.load(:parser, @parser_name || Crabfarm.config.parser)
end

.snapshot_path(_name = nil) ⇒ Object



21
22
23
24
# File 'lib/crabfarm/base_reducer.rb', line 21

def self.snapshot_path(_name=nil)
  _name = self.to_s.underscore if _name.nil?
  Utils::Resolve.snapshot_path _name, parser.format
end

.use_parser(_parser_name) ⇒ Object



13
14
15
# File 'lib/crabfarm/base_reducer.rb', line 13

def self.use_parser(_parser_name)
  @parser_name = _parser_name
end

Instance Method Details

#__getobj__Object



52
53
54
# File 'lib/crabfarm/base_reducer.rb', line 52

def __getobj__
  @document
end

#__setobj__(obj) ⇒ Object



56
57
58
# File 'lib/crabfarm/base_reducer.rb', line 56

def __setobj__(obj)
  @document = obj
end

#as_json(_options = nil) ⇒ Object



44
45
46
# File 'lib/crabfarm/base_reducer.rb', line 44

def as_json(_options=nil)
  field_hash
end

#parserObject



26
27
28
# File 'lib/crabfarm/base_reducer.rb', line 26

def parser
  self.class.parser
end

#runObject

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/crabfarm/base_reducer.rb', line 40

def run
  raise NotImplementedError.new
end

#to_json(_options = nil) ⇒ Object



48
49
50
# File 'lib/crabfarm/base_reducer.rb', line 48

def to_json(_options=nil)
  field_hash.to_json _options
end