Class: Bookwatch::HtmlDocumentManipulator
- Inherits:
-
Object
- Object
- Bookwatch::HtmlDocumentManipulator
- Defined in:
- lib/bookwatch/html_document_manipulator.rb
Instance Method Summary collapse
- #read_html_in_tag(document: nil, tag: nil) ⇒ Object
- #set_attribute(document: nil, selector: nil, attribute: nil, value: nil) ⇒ Object
Instance Method Details
#read_html_in_tag(document: nil, tag: nil) ⇒ Object
15 16 17 18 |
# File 'lib/bookwatch/html_document_manipulator.rb', line 15 def read_html_in_tag(document: nil, tag: nil) doc = Nokogiri::HTML(document) doc.css(tag).inner_html end |
#set_attribute(document: nil, selector: nil, attribute: nil, value: nil) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/bookwatch/html_document_manipulator.rb', line 5 def set_attribute(document: nil, selector: nil, attribute: nil, value: nil) doc = Nokogiri::HTML.fragment(document) node_set = doc.css(selector) node_set.attr(attribute, value) doc.to_html end |