Class: Lazibi::EngineBase

Inherits:
Object
  • Object
show all
Includes:
Helper::ApplicationHelper
Defined in:
lib/core/engine_base.rb

Direct Known Subclasses

BeautifyEngine

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::ApplicationHelper

#skip_notice

Constructor Details

#initializeEngineBase

Returns a new instance of EngineBase.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/core/engine_base.rb', line 16

def initialize
  @filters = []
  @up_path = []
  @down_path = []
  filter_dir = File.dirname(__FILE__) + '/../filter'

  Dir.open(filter_dir).each do |fn|
    next unless fn =~ /[.]rb$/
    require fn
    @filters << fn.scan(/(.*)[.]/).to_s.to_sym
  end
end

Instance Attribute Details

#down_pathObject (readonly)

Returns the value of attribute down_path.



13
14
15
# File 'lib/core/engine_base.rb', line 13

def down_path
  @down_path
end

#filtersObject (readonly)

Returns the value of attribute filters.



14
15
16
# File 'lib/core/engine_base.rb', line 14

def filters
  @filters
end

#up_pathObject (readonly)

Returns the value of attribute up_path.



12
13
14
# File 'lib/core/engine_base.rb', line 12

def up_path
  @up_path
end

Instance Method Details

#down(source) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/core/engine_base.rb', line 55

def down(source)
  return source if source.blank?
  transcript = source
  if transcript.split("\n").first == skip_notice
    return source.split("\n")[1..-1].join("\n")
  end

  @down_path.each do |step|
    class_name = step.to_s.camelize
    filter = Filter.const_get(class_name).new
    transcript = filter.down(transcript)
  end
  transcript
end

#go_down(*paths) ⇒ Object



34
35
36
# File 'lib/core/engine_base.rb', line 34

def go_down(*paths)
  @down_path += Array(paths)
end

#go_up(*paths) ⇒ Object



30
31
32
# File 'lib/core/engine_base.rb', line 30

def go_up(*paths)
  @up_path += Array(paths)
end

#to_sObject



70
71
72
# File 'lib/core/engine_base.rb', line 70

def to_s
  'up_path: ' + @up_path.to_s + "\n" + 'down_path: ' + @down_path.to_s
end

#up(source) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/core/engine_base.rb', line 38

def up(source)
  return source if source.blank?
  transcript = source
  valid = true
  @up_path.each do |step|
    class_name = step.to_s.camelize
    filter = Filter.const_get(class_name).new
    transcript = filter.up(transcript)
    unless transcript
      valid = false
      break
    end
  end

  valid ? transcript : skip_notice + "\n" + source
end