class Sablon::DOM::FileHandler
An abstract class used to setup other file handling classes
Public Class Methods
extend_model(model_klass, &block)
click to toggle source
extends the Model
class using instance eval with a block argument
# File lib/sablon/document_object_model/file_handler.rb, line 7 def self.extend_model(model_klass, &block) model_klass.instance_eval(&block) end
new(content)
click to toggle source
All subclasses should be initialized only accepting the content as a single argument.
# File lib/sablon/document_object_model/file_handler.rb, line 13 def initialize(content); end
Public Instance Methods
max_attribute_value(xml_node, selector, attr_name, query_method: :xpath)
click to toggle source
Finds the maximum value of an attribute by converting it to an integer. Non numeric portions of values are ignored. The method can be either xpath or css, xpath being the default.
# File lib/sablon/document_object_model/file_handler.rb, line 18 def max_attribute_value(xml_node, selector, attr_name, query_method: :xpath) xml_node.send(query_method, selector).map.inject(0) do |max, node| next max unless (match = node.attr(attr_name).match(/(\d+)/)) [max, match[1].to_i].max end end