Class: Prolog::Services::ReplaceContent
- Inherits:
-
Object
- Object
- Prolog::Services::ReplaceContent
- 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
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#markers ⇒ Object
Returns the value of attribute markers.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Class Method Summary collapse
- .set_content(obj, content) ⇒ Object
- .set_endpoints(obj, endpoints) ⇒ Object
- .set_replacement(obj, replacement) ⇒ Object
Instance Method Summary collapse
- #convert ⇒ Object
-
#converted_content ⇒ Object
rubocop:enable.
-
#initialize(content: '', endpoints: (-1..-1), replacement: '') ⇒ ReplaceContent
constructor
A new instance of ReplaceContent.
- #valid? ⇒ Boolean
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
#content ⇒ Object (readonly)
Returns the value of attribute content.
13 14 15 |
# File 'lib/prolog/services/replace_content.rb', line 13 def content @content end |
#endpoints ⇒ Object (readonly)
Returns the value of attribute endpoints.
13 14 15 |
# File 'lib/prolog/services/replace_content.rb', line 13 def endpoints @endpoints end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
13 14 15 |
# File 'lib/prolog/services/replace_content.rb', line 13 def errors @errors end |
#markers ⇒ Object
Returns the value of attribute markers.
13 14 15 |
# File 'lib/prolog/services/replace_content.rb', line 13 def markers @markers end |
#replacement ⇒ Object (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
#convert ⇒ Object
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_content ⇒ Object
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
44 45 46 |
# File 'lib/prolog/services/replace_content.rb', line 44 def valid? errors.empty? end |