Class: Mdextab::Td

Inherits:
Object
  • Object
show all
Defined in:
lib/mdextab/td.rb

Overview

TDトークン対応クラス

Instance Method Summary collapse

Constructor Details

#initialize(lineno, attr = nil) ⇒ Td

初期化

Parameters:

  • lineno (String)

    TDトークン出現行の行番号

  • attr (String) (defaults to: nil)

    TDトークンの属性



10
11
12
13
14
# File 'lib/mdextab/td.rb', line 10

def initialize(lineno, attr=nil)
  @lineno = lineno
  @attr = attr
  @content = ""
end

Instance Method Details

#add(content, condnese) ⇒ void

This method returns an undefined value.

TDトークンのコンテンツ追加

Parameters:

  • content (String)

    TDトークンのコンテンツ

  • condense (Boolean)

    文字列化方法 true:改行を含めない false:改行を含める



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mdextab/td.rb', line 22

def add(content, condnese)
  if condnese
    if @content
      if @contnet.match?(/^\s*$/)
        @content = content.to_s
      else
        @content += content.to_s
      end
    else
      @content = content.to_s
    end
  elsif content
    @content = [@content, content].join("\n")
  end
end

#to_sString

tdの文字列化

Returns:

  • (String)

    HTMLのTDタグとして文字列化したもの



42
43
44
45
46
47
48
# File 'lib/mdextab/td.rb', line 42

def to_s
  if @attr.nil?
    %Q(<td>#{@content}</td>)
  else
    %Q(<td #{@attr}>#{@content}</td>)
  end
end