Class: Facwparser::Element::TableData

Inherits:
ElementBase 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.



139
140
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
# File 'lib/facwparser/element.rb', line 139

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.



138
139
140
# File 'lib/facwparser/element.rb', line 138

def elements
  @elements
end

Instance Method Details

#render_html(options) ⇒ Object



170
171
172
173
174
# File 'lib/facwparser/element.rb', line 170

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