Class: Prolog::Services::ReplaceContent

Inherits:
Object
  • Object
show all
Defined in:
lib/prolog/services/replace_content.rb,
lib/prolog/services/replace_content/version.rb,
lib/prolog/services/replace_content/splitter/paired.rb,
lib/prolog/services/replace_content/splitter/factory.rb,
lib/prolog/services/replace_content/splitter/symmetric.rb,
lib/prolog/services/replace_content/splitter/paired_params.rb,
lib/prolog/services/replace_content/splitter/splitter_params.rb,
lib/prolog/services/replace_content/splitter/symmetric_params.rb

Overview

Replaces content within an HTML string based on endpoints and content.

Defined Under Namespace

Modules: Splitter

Constant Summary collapse

VERSION =
'0.1.3'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content: '', endpoints: (-1..-1), replacement: '') ⇒ ReplaceContent

Returns a new instance of ReplaceContent.



15
16
17
18
19
20
21
22
# File 'lib/prolog/services/replace_content.rb', line 15

def initialize(content: '', endpoints: (-1..-1), replacement: '')
  @content = content
  @endpoints = endpoints
  @replacement = replacement
  @content_after_conversion = nil
  @errors = {}
  self
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



13
14
15
# File 'lib/prolog/services/replace_content.rb', line 13

def content
  @content
end

#endpointsObject (readonly)

Returns the value of attribute endpoints.



13
14
15
# File 'lib/prolog/services/replace_content.rb', line 13

def endpoints
  @endpoints
end

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/prolog/services/replace_content.rb', line 13

def errors
  @errors
end

#markersObject

Returns the value of attribute markers.



13
14
15
# File 'lib/prolog/services/replace_content.rb', line 13

def markers
  @markers
end

#replacementObject (readonly)

Returns the value of attribute replacement.



13
14
15
# File 'lib/prolog/services/replace_content.rb', line 13

def replacement
  @replacement
end

Class Method Details

.set_content(obj, content) ⇒ Object



48
49
50
51
# File 'lib/prolog/services/replace_content.rb', line 48

def self.set_content(obj, content)
  new endpoints: obj.endpoints, replacement: obj.replacement,
      content: content
end

.set_endpoints(obj, endpoints) ⇒ Object



53
54
55
56
# File 'lib/prolog/services/replace_content.rb', line 53

def self.set_endpoints(obj, endpoints)
  new content: obj.content, replacement: obj.replacement,
      endpoints: endpoints
end

.set_replacement(obj, replacement) ⇒ Object



58
59
60
61
# File 'lib/prolog/services/replace_content.rb', line 58

def self.set_replacement(obj, replacement)
  new content: obj.content, endpoints: obj.endpoints,
      replacement: replacement
end

Instance Method Details

#convertObject



24
25
26
27
28
29
30
# File 'lib/prolog/services/replace_content.rb', line 24

def convert
  validate
  return false unless valid?

  set_converted_content
  valid?
end

#converted_contentObject

rubocop:enable



33
34
35
36
# File 'lib/prolog/services/replace_content.rb', line 33

def converted_content
  errors[:conversion] = ['not called'] unless @content_after_conversion
  @content_after_conversion || :oops
end

#valid?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/prolog/services/replace_content.rb', line 44

def valid?
  errors.empty?
end