Class: Wikitree::Template::Param

Inherits:
Object
  • Object
show all
Defined in:
lib/wikitree/nodes.rb

Overview

use a nested param class - why? why not?

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

note: starts with 1 (NOT 0)



60
61
62
# File 'lib/wikitree/nodes.rb', line 60

def name
  @name
end

#numObject (readonly)

note: starts with 1 (NOT 0)



60
61
62
# File 'lib/wikitree/nodes.rb', line 60

def num
  @num
end

#valueObject (readonly)

note: starts with 1 (NOT 0)



60
61
62
# File 'lib/wikitree/nodes.rb', line 60

def value
  @value
end

Instance Method Details

#inspectObject



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_textObject



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_wikiObject



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