Class: Mdextab::Th

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

Overview

THトークン対応クラス

Instance Method Summary collapse

Constructor Details

#initialize(lineno, attr = nil) ⇒ Th

初期化

Parameters:

  • lineno (String)

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

  • attr (String) (defaults to: nil)

    THトークンの属性



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

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

Instance Method Details

#add(content, condense) ⇒ void

This method returns an undefined value.

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

Parameters:

  • content (String)

    THトークンのコンテンツ

  • condense (Boolean)

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



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

def add(content, condense)
  if condense
    if @content
      if @content.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

thの文字列化

Returns:

  • (String)

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



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

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