Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're willing to take this approach you should probably scan the filed for the mathing string and then <code>include</code> the right one.</p> <p>In the same situation I attempted a different approach. I'm extending the module with new methods, @@registering them so that I won't register two identically named methods. So far it works good, though the project I started is nowhere near leaving the specific domain of one tangled mess of a particular web-site.</p> <p>This is the main file.</p> <pre><code>module Onigiri extend self @@registry ||= {} class OnigiriHandlerTaken &lt; StandardError def description "There was an attempt to override registered handler. This usually indicates a bug in Onigiri." end end def clean(data, *params) dupe = Onigiri::Document.parse data params.flatten.each do |method| dupe = dupe.send(method) if @@registry[method] end dupe.to_html end class Document &lt; Nokogiri::HTML::DocumentFragment end private def register_handler(name) unless @@registry[name] @@registry[name] = true else raise OnigiriHandlerTaken end end end </code></pre> <p>And here's the extending file.</p> <pre><code># encoding: utf-8 module Onigiri register_handler :fix_backslash class Document def fix_backslash dupe = dup attrset = ['src', 'longdesc', 'href', 'action'] dupe.css("[#{attrset.join('], [')}]").each do |target| attrset.each do |attr| target[attr] = target[attr].gsub("\\", "/") if target[attr] end end dupe end end end </code></pre> <p>Another way I see is to use a set of different (but behaviorally indistinguishable) classes with a simple decision making mechanism to call a right one. A simple hash that holds class names and corresponding url_matcher would probably suffice.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload