Class: HtmlSurgeon::Service
- Inherits:
-
Object
- Object
- HtmlSurgeon::Service
- Defined in:
- lib/html_surgeon/service.rb
Instance Attribute Summary collapse
-
#given_html ⇒ Object
readonly
Returns the value of attribute given_html.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #audit? ⇒ Boolean
- #clear_audit ⇒ Object
- #css(css_selector) ⇒ Object
- #html ⇒ Object
-
#initialize(html_string, audit: false, **extra_options) ⇒ Service
constructor
A new instance of Service.
-
#rollback(change_set: nil, changed_at: nil, changed_from: nil) ⇒ Object
returns the number of changes performed.
- #xpath(xpath_selector) ⇒ Object
Constructor Details
#initialize(html_string, audit: false, **extra_options) ⇒ Service
Returns a new instance of Service.
5 6 7 8 9 |
# File 'lib/html_surgeon/service.rb', line 5 def initialize(html_string, audit: false, **) @given_html = html_string.to_s @audit = audit = .merge audit: audit end |
Instance Attribute Details
#given_html ⇒ Object (readonly)
Returns the value of attribute given_html.
3 4 5 |
# File 'lib/html_surgeon/service.rb', line 3 def given_html @given_html end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/html_surgeon/service.rb', line 3 def end |
Instance Method Details
#audit? ⇒ Boolean
15 16 17 |
# File 'lib/html_surgeon/service.rb', line 15 def audit? !!@audit end |
#clear_audit ⇒ Object
40 41 42 43 44 45 |
# File 'lib/html_surgeon/service.rb', line 40 def clear_audit doc.css("[#{DATA_CHANGE_AUDIT_ATTRIBUTE}]").reduce(0) do |sum, node| cleaner = NodeServices::AuditCleaner.new node: node sum + cleaner.call end end |
#css(css_selector) ⇒ Object
19 20 21 22 |
# File 'lib/html_surgeon/service.rb', line 19 def css(css_selector) node_set = doc.css(css_selector) ChangeSet.create(node_set, self) end |
#html ⇒ Object
11 12 13 |
# File 'lib/html_surgeon/service.rb', line 11 def html @html ||= doc.to_html end |
#rollback(change_set: nil, changed_at: nil, changed_from: nil) ⇒ Object
returns the number of changes performed
30 31 32 33 34 35 36 37 38 |
# File 'lib/html_surgeon/service.rb', line 30 def rollback(change_set: nil, changed_at: nil, changed_from: nil) doc.css("[#{DATA_CHANGE_AUDIT_ATTRIBUTE}]").reduce(0) do |sum, node| reverser = NodeServices::Reverser.new node: node, change_set: change_set, changed_at: changed_at, changed_from: changed_from sum + reverser.call end end |
#xpath(xpath_selector) ⇒ Object
24 25 26 27 |
# File 'lib/html_surgeon/service.rb', line 24 def xpath(xpath_selector) node_set = doc.xpath(xpath_selector) ChangeSet.create(node_set, self) end |