6.47. kink/doc/model/SECTION¶
6.47.1. section型¶
Kinkdocの節。
マニュアルの「Kinkdoc: API文書化システム」 → 「データモデル」を見よう。
6.47.1.1. Section.title¶
titleは、Sectionのタイトルのstrを戻す。
6.47.1.2. Section.blocks¶
blocksは、Sectionのblock値のvecを戻す。
6.47.1.3. Section.subsections¶
subsectionsは、Sectionの小節であるsection値のvecを戻す。
6.47.1.4. Section.to_json_val¶
to_json_valは、SectionのJSON値を戻す。
マニュアルの「Kinkdoc: API文書化システム」 → 「データモデル」 → 「JSONスキーマ」を見よう。
例
:SECTION.require_from('kink/doc/model/')
:BLOCK.require_from('kink/doc/model/')
:BLOCK_TYPE.require_from('kink/doc/model/')
:JSON.require_from('kink/json/')
:Doc <- SECTION.new(
'Doc title'
[ BLOCK.new(BLOCK_TYPE.paragraph 'hey!') ]
[ SECTION.new(
'Section title'
[]
[]
)
]
)
:Json_val <- Doc.to_json_val
stdout.print_line(JSON.stringify(Json_val))
# Output:
# {
# "blocks": [
# {
# "text": "hey!",
# "type": "paragraph"
# }
# ],
# "subsections": [
# {
# "blocks": [],
# "subsections": [],
# "title": "Section title"
# }
# ],
# "title": "Doc title"
# }
6.47.1.5. Section.depth¶
depthは、Sectionの木の深さを、整数のnum値として戻す。
sectionの深さは次のように定義される:
• sectionが小節をひとつも持たない場合、深さは1である。
• sectionがひとつ以上の小節を持っている場合、sectionの深さは、小説の深さの最大値に1を足したものになる。
6.47.1.6. Section.limit_depth(Max_depth)¶
Sectionの深さがMax_depthよりも大きいとき、limit_depthは、Max_depthよりも深くないsectionを戻す。結果のsectionは、Sectionと同じ小節の集合を持つが、Max_depthよりも深い枝の部分はフラット化される。
Sectionの深さがMax_depth以下のとき、limit_depthはSection自体を戻す。
事前条件
Max_depthは、2以上の整数のnum値でなければならない。
事後条件
Result.depthはMax_depth以下である。
6.47.1.7. X == Y¶
ふたつの節は、等しいタイトル、等しいブロックの配列、等しい小節の配列を持っているときに等しい。
事前条件
Yはsectionでなければならない。
6.47.2. SECTION.new(Title Blocks Subsections)¶
newは新しいsectionを戻す。
事前条件
Titleは空でないstrでなければならない。また、空白文字で開始、終了せず、ASCII制御文字を含まない文字列でなければならない。
Blocksはblock値のvecでなければならない。
Subsectionsはsection値のvecでなければならない。
6.47.3. SECTION.is?(Val)¶
is?は、Valがsection値であるかどうかを戻す。
6.47.4. SECTION.from_json_val(Json_val ...[$config={}])¶
from_json_valは、Json_valからsection値を作る。
コンフィグメソッド:
• C.on_success($success): default = VAL.identity
• C.on_error($error): default = $raise
Json_valがkinkdocの節のJSONスキーマに合致するとき、from_json_valは、sectionを渡して$successを末尾呼び出しする。
Json_valがkinkdocの節のJSONスキーマに合致しないとき、from_json_valは、エラーメッセージのstrを渡して$errorを末尾呼び出しする。
事前条件
Json_valはJSON値でなければならない。
例
:SECTION.require_from('kink/doc/model/')
:FLAT_MAP.require_from('kink/container/')
:Json_val <- FLAT_MAP.of(
'title' 'Greeting program'
'blocks' [
FLAT_MAP.of(
'type' 'paragraph'
'text' 'This program outputs "hello world" to the standard output.'
)
FLAT_MAP.of(
'type' 'paragraph'
'text' 'The exit status hall be 0 when it terminates without an error.'
)
]
'subsections' []
)
:Section <- SECTION.from_json_val(Json_val)
stdout.print_line(Section.repr)
# => (section title="Greeting program" blocks=[(block type=BLOCK_TYPE.paragraph text="This program outputs \"hello world\" to the standard output.") (block type=BLOCK_TYPE.paragraph text="The exit status hall be 0 when it terminates without an error.")] subsections=[])