Class: Wikitree::Template::Param
- Inherits:
-
Object
- Object
- Wikitree::Template::Param
- Defined in:
- lib/wikitree/nodes.rb
Overview
use a nested param class - why? why not?
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
note: starts with 1 (NOT 0).
-
#num ⇒ Object
readonly
note: starts with 1 (NOT 0).
-
#value ⇒ Object
readonly
note: starts with 1 (NOT 0).
Instance Method Summary collapse
-
#initialize(num, name, value) ⇒ Param
constructor
A new instance of Param.
- #inspect ⇒ Object
- #pretty_print(pp) ⇒ Object
- #to_text ⇒ Object
- #to_wiki ⇒ Object
Constructor Details
#initialize(num, name, value) ⇒ Param
Returns a new instance of Param.
63 64 65 66 67 |
# File 'lib/wikitree/nodes.rb', line 63 def initialize( num, name, value ) @num = num # todo/check: rename to index or such - why? why not? @name = name @value = value end |
Instance Attribute Details
#name ⇒ Object (readonly)
note: starts with 1 (NOT 0)
60 61 62 |
# File 'lib/wikitree/nodes.rb', line 60 def name @name end |
#num ⇒ Object (readonly)
note: starts with 1 (NOT 0)
60 61 62 |
# File 'lib/wikitree/nodes.rb', line 60 def num @num end |
#value ⇒ Object (readonly)
note: starts with 1 (NOT 0)
60 61 62 |
# File 'lib/wikitree/nodes.rb', line 60 def value @value end |
Instance Method Details
#inspect ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/wikitree/nodes.rb', line 69 def inspect if @name "#<_#{num} (#{@name}): #{@value.inspect}>" else "#<_#{num}: #{@value.inspect}>" end end |
#pretty_print(pp) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/wikitree/nodes.rb', line 77 def pretty_print(pp) if @name pp.text "#<_#{num} (#{@name}): " else pp.text "#<_#{num}: " end pp.breakable pp.pp @value pp.text ">" end |
#to_text ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/wikitree/nodes.rb', line 88 def to_text if value.empty? ## note: value might be nil (convert to "") '' else value.map { |node| node.to_text }.join end end |
#to_wiki ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/wikitree/nodes.rb', line 95 def to_wiki if value.empty? ## note: value might be nil (convert to "") '' else value.map { |node| node.to_wiki }.join end end |