class CSL::TextNode

Attributes

text[RW]

Public Class Methods

create(name, attributes = {}, &block) click to toggle source

@override

# File lib/csl/node.rb, line 562
def create(name, attributes = {}, &block)
  klass = constantize(name)

  node = (klass || TextNode).new(attributes, &block)
  node.nodename = name
  node
end
new(argument = '') { |self| ... } click to toggle source

TextNodes quack like a string. def_delegators :to_s, *String.instance_methods(false).reject do |m|

m.to_s =~ /^\W|!$|(?:^(?:hash|eql?|to_s|length|size|inspect)$)/

end

String.instance_methods(false).select { |m| m.to_s =~ /!$/ }.each do |m|

define_method(m) do
  content.send(m) if content.respond_to?(m)
end

end

Calls superclass method CSL::Node::new
# File lib/csl/node.rb, line 588
def initialize(argument = '')
  case
  when argument.respond_to?(:each_pair)
    super
  when argument.respond_to?(:to_s)
    super({})
    @text = argument.to_s
    yield self if block_given?
  else
    raise ArgumentError, "failed to create text node from #{argument.inspect}"
  end
end

Public Instance Methods

empty?() click to toggle source
# File lib/csl/node.rb, line 612
def empty?
  text.nil? || text.empty?
end
initialize_copy(other) click to toggle source
Calls superclass method CSL::Node#initialize_copy
# File lib/csl/node.rb, line 601
def initialize_copy(other)
  super
  @text = other.text
end
inspect() click to toggle source
# File lib/csl/node.rb, line 620
def inspect
  "#<#{[self.class.name, text.inspect, *attribute_assignments].join(' ')}>"
end
tags() click to toggle source
# File lib/csl/node.rb, line 616
def tags
  ["<#{attribute_assignments.unshift(nodename).join(' ')}>#{to_s}</#{nodename}>"]
end
textnode?() click to toggle source
# File lib/csl/node.rb, line 606
def textnode?
  true
end
to_s() click to toggle source
# File lib/csl/node.rb, line 573
def to_s
  CSL.encode_xml_text text.to_s.strip
end