Class: Facwparser::Element::TableData

Inherits:
TableRow show all
Defined in:
lib/facwparser/element.rb

Instance Attribute Summary collapse

Attributes inherited from ElementBase

#children, #source

Instance Method Summary collapse

Methods inherited from ElementBase

#==, #render_text

Constructor Details

#initialize(source, value) ⇒ TableData

Returns a new instance of TableData.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/facwparser/element.rb', line 141

def initialize(source, value)
  super(source)
  @elements = []
  element = ''
  s = StringScanner.new(value[1..-1])
  in_link = false
  while s.rest?
    case
    when s.scan(/[^|\[\]]+/) || s.scan(/\\\[/) || s.scan(/\\\]/) || s.scan(/\\\|/)
      element += s[0]
    when s.scan(/\[/)
      in_link = true
      element += s[0]
    when s.scan(/\]/)
      in_link = false
      element += s[0]
    when s.scan(/\|/)
      if in_link
        element += s[0]
      else
        @elements << element
        element = ''
      end
    else
      element += s.rest
      break
    end
  end
  @elements << element if !element.empty?
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



140
141
142
# File 'lib/facwparser/element.rb', line 140

def elements
  @elements
end

Instance Method Details

#render_html(options) ⇒ Object



172
173
174
175
176
# File 'lib/facwparser/element.rb', line 172

def render_html(options)
  "<tr>" +
    @elements.map { |e| render_html_by_name_and_children('td', Parser.parse_value(e, options), options) }.join() +
    "</tr>"
end