Sha256: 9a2fbed2de67639121693cfb057c0ee9862636f936fb920fff4855489f7551f7
Contents?: true
Size: 861 Bytes
Versions: 2
Compression:
Stored size: 861 Bytes
Contents
# Author:: TAC (tac@tac42.net) require_relative 'yasuri_node' module Yasuri class TextNode include Node def initialize(xpath, name, children = [], truncate: nil, proc:nil) super(xpath, name, children) truncate = Regexp.new(truncate) if not truncate.nil? # regexp or nil @truncate = truncate @truncate = Regexp.new(@truncate.to_s) if not @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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yasuri-2.0.13 | lib/yasuri/yasuri_text_node.rb |
yasuri-2.0.12 | lib/yasuri/yasuri_text_node.rb |