class Yasuri::TextNode
Public Class Methods
new(xpath, name, children = [], **opt)
click to toggle source
Calls superclass method
Yasuri::Node::new
# File lib/yasuri/yasuri_text_node.rb, line 8 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
Public Instance Methods
inject(_agent, page, _opt = {}, element = page)
click to toggle source
# File lib/yasuri/yasuri_text_node.rb, line 21 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
node_type_str()
click to toggle source
# File lib/yasuri/yasuri_text_node.rb, line 39 def node_type_str "text".freeze end
opts()
click to toggle source
# File lib/yasuri/yasuri_text_node.rb, line 35 def opts { truncate: @truncate, proc: @proc } end