Class: Sablon::DOM::FileHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/sablon/document_object_model/file_handler.rb

Overview

An abstract class used to setup other file handling classes

Direct Known Subclasses

ContentTypes, Numbering, Relationships

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ FileHandler

All subclasses should be initialized only accepting the content as a single argument.



13
# File 'lib/sablon/document_object_model/file_handler.rb', line 13

def initialize(content); end

Class Method Details

.extend_model(model_klass, &block) ⇒ Object

extends the Model class using instance eval with a block argument



7
8
9
# File 'lib/sablon/document_object_model/file_handler.rb', line 7

def self.extend_model(model_klass, &block)
  model_klass.instance_eval(&block)
end

Instance Method Details

#max_attribute_value(xml_node, selector, attr_name, query_method: :xpath) ⇒ Object

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.



18
19
20
21
22
23
# 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