Sha256: 689ff632091a23026c6ff804073405b6f2eb2697539bf234585f9af6c9f333a6

Contents?: true

Size: 622 Bytes

Versions: 2

Compression:

Stored size: 622 Bytes

Contents

# Author::    TAC (tac@tac42.net)

require_relative 'yasuri_node'

module Yasuri
  class TextNode
    include Node

    def initialize(xpath, name, children = [], truncate: 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?
    end

    def inject(agent, page, opt = {})
      node = page.search(@xpath)
      text = node.text.to_s

      text = text[@truncate, 0] if @truncate

      text.to_s
    end
    def opts
      {truncate:@truncate}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yasuri-0.0.9 lib/yasuri/yasuri_text_node.rb
yasuri-0.0.8 lib/yasuri/yasuri_text_node.rb