Class: Text::Gen::Filter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/text/gen/filter/base.rb

Overview

Base class for all filters Provides common utilities and template method pattern

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter, depth) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/text/gen/filter/base.rb', line 9

def initialize(filter, depth)
  @filter = filter
  @depth = depth
end

Class Method Details

.filter_keyObject



46
47
48
# File 'lib/text/gen/filter/base.rb', line 46

def filter_key
  filter_name.downcase
end

.filter_nameObject



42
43
44
# File 'lib/text/gen/filter/base.rb', line 42

def filter_name
  @filter_name ||= name.split("::").last
end

Instance Method Details

#component_keyObject



14
15
16
# File 'lib/text/gen/filter/base.rb', line 14

def component_key
  "fn(#{to_s})"
end

#keyObject

Shared utilities



19
20
21
22
23
# File 'lib/text/gen/filter/base.rb', line 19

def key
  return @key if defined?(@key)

  @key = @filter["key"].nil? || @filter["key"].empty? ? nil : @filter["key"]
end

#to_sObject



35
36
37
38
39
# File 'lib/text/gen/filter/base.rb', line 35

def to_s
  return "#{ type }:#{ key }:#{ value }" if value
  return "#{ type }:#{ key }" if key
  type
end

#typeObject



31
32
33
# File 'lib/text/gen/filter/base.rb', line 31

def type
  @type ||= @filter["type"]
end

#valueObject



25
26
27
28
29
# File 'lib/text/gen/filter/base.rb', line 25

def value
  return @value if defined?(@value)

  @value = @filter["value"].nil? || @filter["value"].empty? ? nil : @filter["value"]
end