Class: CSL::TextNode
Direct Known Subclasses
Info::DependentStyle, Info::Email, Info::Id, Info::Name, Info::Published, Info::Rights, Info::Summary, Info::Title, Info::TitleShort, Info::URI, Info::Updated, Locale::Term::Multiple, Locale::Term::Single
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Attributes inherited from Node
Attributes included from Treelike
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(argument = '') ⇒ TextNode
constructor
TextNodes quack like a string.
- #inspect ⇒ Object
- #tags ⇒ Object
- #textnode? ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from Node
#<=>, #attribute?, #attributes?, #attributes_for, constantize, create_attributes, #custom_attributes, #deep_copy, #default_attribute?, #default_attributes, default_attributes, #each, #exact_match?, #formatting_options, #has_attributes?, #has_default_attributes?, #has_language?, hide_default_attributes!, hide_default_attributes?, #initialize_copy, match?, #match?, matches?, parse, parse!, #save_to, show_default_attributes!, types
Methods included from PrettyPrinter
Methods included from Treelike
#<<, #add_child, #add_children, #ancestors, #delete_child, #delete_children, #depth, #descendants, #each_ancestor, #each_child, #each_descendant, #each_sibling, #find_child, #find_children, #has_children?, #root, #root?, #siblings, #unlink
Constructor Details
#initialize(argument = '') ⇒ TextNode
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
522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/csl/node.rb', line 522 def initialize(argument = '') case when argument.is_a?(Hash) 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 |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
505 506 507 |
# File 'lib/csl/node.rb', line 505 def text @text end |
Class Method Details
.create(name, attributes = {}, &block) ⇒ Object
496 497 498 499 500 501 502 |
# File 'lib/csl/node.rb', line 496 def create(name, attributes = {}, &block) klass = constantize(name) node = (klass || TextNode).new(attributes, &block) node.nodename = name node end |
Instance Method Details
#empty? ⇒ Boolean
539 540 541 |
# File 'lib/csl/node.rb', line 539 def empty? text.nil? || text.empty? end |
#inspect ⇒ Object
547 548 549 |
# File 'lib/csl/node.rb', line 547 def inspect "#<#{[self.class.name, text.inspect, *attribute_assignments].join(' ')}>" end |
#tags ⇒ Object
543 544 545 |
# File 'lib/csl/node.rb', line 543 def ["<#{attribute_assignments.unshift(nodename).join(' ')}>#{to_s}</#{nodename}>"] end |
#textnode? ⇒ Boolean
535 536 537 |
# File 'lib/csl/node.rb', line 535 def textnode? true end |
#to_s ⇒ Object
507 508 509 |
# File 'lib/csl/node.rb', line 507 def to_s CSL.encode_xml_text text.to_s.strip end |