Class: MacroHub
- Inherits:
-
Object
- Object
- MacroHub
- Defined in:
- lib/macrohub.rb
Instance Attribute Summary collapse
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
Instance Method Summary collapse
- #import_xml(raws) ⇒ Object
-
#initialize(obj = nil) ⇒ MacroHub
constructor
A new instance of MacroHub.
- #to_doc ⇒ Object
- #to_rowx ⇒ Object (also: #to_s)
- #to_xml ⇒ Object
Constructor Details
#initialize(obj = nil) ⇒ MacroHub
Returns a new instance of MacroHub.
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'lib/macrohub.rb', line 509 def initialize(obj=nil) if obj then s, _ = RXFHelper.read(obj) if s[0] == '<' import_xml(s) else import_xml(RowX.new(s.gsub(/^#.*/,'')).to_xml) end else @macros = [] end end |
Instance Attribute Details
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
507 508 509 |
# File 'lib/macrohub.rb', line 507 def macros @macros end |
Instance Method Details
#import_xml(raws) ⇒ Object
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/macrohub.rb', line 528 def import_xml(raws) s = RXFHelper.read(raws).first puts 's: ' + s.inspect if $debug doc = Rexle.new(s) puts 'after doc' if $debug @macros = doc.root.xpath('item').map do |node| macro = Macro.new node.text('macro') macro.import_xml(node) macro end end |
#to_doc ⇒ Object
545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/macrohub.rb', line 545 def to_doc() doc = Rexle.new('<macros/>') @macros.each do |macro| puts 'macro: ' + macro.inspect if $debug doc.root.add macro.to_node end return doc end |
#to_rowx ⇒ Object Also known as: to_s
558 559 560 561 562 563 564 |
# File 'lib/macrohub.rb', line 558 def to_rowx() s = '' s += "title: %s\n%s\n\n" % [@title, '-' * 50] if @title s += @macros.collect(&:to_rowx).join("\n\n#{'-'*50}\n\n") end |
#to_xml ⇒ Object
568 569 570 |
# File 'lib/macrohub.rb', line 568 def to_xml() to_doc.xml pretty: true end |