Sha256: fbb6ec4263dcb4fb692085a696e3fc36b00e944df60fbc4b4b98fdbbc9df9f08
Contents?: true
Size: 922 Bytes
Versions: 2
Compression:
Stored size: 922 Bytes
Contents
require_relative 'yasuri_node' module Yasuri class TextNode include Node def initialize(xpath, name, children = [], **opt) super(xpath, name, children) truncate = opt[:truncate] proc = opt[:proc] truncate = Regexp.new(truncate) unless truncate.nil? # regexp or nil @truncate = truncate @truncate = Regexp.new(@truncate.to_s) unless @truncate.nil? @proc = proc.nil? ? nil : proc.to_sym end def inject(_agent, page, _opt = {}, element = page) node = element.search(@xpath) text = node.text.to_s if @truncate matches = @truncate.match(text) text = matches ? matches[1] || matches[0] || text : "" end text = text.__send__(@proc) if @proc && text.respond_to?(@proc) text end def opts { truncate: @truncate, proc: @proc } end def node_type_str "text".freeze end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yasuri-3.3.2 | lib/yasuri/yasuri_text_node.rb |
yasuri-3.3.1 | lib/yasuri/yasuri_text_node.rb |