relaton-iec 1.7.8 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ module BasicBlock
2
+ class Formula
3
+ #
4
+ # @param [String] id
5
+ # @param [BasicBlock::Stem] content
6
+ # @param [Array<BasicBlock::Note>] note
7
+ # @param [Hash] args
8
+ # @option args [Boolean, nil] :unnumbered
9
+ # @option args [String, nil] :subsequence
10
+ # @option args [Boolean, nil] :inequality
11
+ # @option args [BasicBlock::Dl, nil] :dl
12
+ #
13
+ def initialize(id:, content:, note:, **args)
14
+ @id = id
15
+ @content = content
16
+ @note = note
17
+ @unnumbered = args[:unnumbered]
18
+ end
19
+
20
+ #
21
+ # @param [Builder] builder
22
+ #
23
+ def to_xml(builder) # rubocop:disable Metrics/CyclomaticComplexity
24
+ f = builder.formula id: @id do |b|
25
+ @content.to_xml b
26
+ @dl&.each { |d| d.to_xml b }
27
+ @note.each { |n| n.to_xml b }
28
+ end
29
+ f[:unnumbered] = @unnumbered if @unnumbered
30
+ f[:subsequence] = @subsequence if @subsequence
31
+ f[:inequality] = @inequality if @ineainequality
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ module BasicBlock
2
+ class Image
3
+ #
4
+ # @param [String] id
5
+ # @param [String] src
6
+ # @param [String] mimetype
7
+ # @param [Hash] args
8
+ # @option args [String] :filename
9
+ #
10
+ def initialize(id:, src:, mimetype:, **args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
11
+ @id = id
12
+ @src = src
13
+ @mimetype = mimetype
14
+ @filename = args[:filename]
15
+ if args[:width] && !args[:width].is_a?(Integer) && args[:width] != "auto"
16
+ warn "[basic-block] WARNING: invalid image width attribute \"#{args[:width]}"
17
+ warn "[basic-block] image width should be integer or \"auto\""
18
+ end
19
+ if args[:height] && !args[:height].is_a?(Integer) && args[:height] != "auto"
20
+ warn "[basic-block] WARNING: invalid image height attribute \"#{args[:height]}"
21
+ warn "[basic-block] image height should be integer or \"auto\""
22
+ end
23
+ @width = args[:width]
24
+ @height = args[:height]
25
+ @alt = args[:alt]
26
+ @title = args[:title]
27
+ @longdesc = args[:longdesc]
28
+ end
29
+
30
+ # @param [Nokogiri::XML::Builder]
31
+ def to_xml(builder) # rubocop:disable Metrics/CyclomaticComplexity
32
+ img = builder.image id: @id, src: @src, mimetype: @mimetype
33
+ img[:filename] = @filename if @filename
34
+ img[:width] = @width if @width
35
+ img[:height] = @height if @height
36
+ img[:alt] = @alt if @alt
37
+ img[:title] = @title if @title
38
+ img[:longdesc] = @longdesc if @longdesc
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ module BasicBlock
2
+ class Index
3
+ #
4
+ # @param [Array<BasicBlock::TextElement] primary
5
+ # @param [Hash] args
6
+ # @option args [String, nil] :to
7
+ # @option args [Array<BasicBlock::TextElement>, nil] :secondary
8
+ # @option args [Array<BasicBlock::TextElement>, nil] :tertiary
9
+ #
10
+ def initialize(primary:, **args)
11
+ @to = args[:to]
12
+ @primary = primary
13
+ @secondary = args[:secondary]
14
+ @tertiary = args[:tertiary]
15
+ end
16
+
17
+ # @param [Nokogiri::XML::Builder] builder
18
+ def to_xml(builder) # rubocop:disable Metrics/CyclomaticComplexity
19
+ idx = builder.index do |b|
20
+ @primary.each { |p| p.to_xml b }
21
+ @secondary&.each { |s| s.to_xml b }
22
+ @tertiary&.each { |t| t.to_xml b }
23
+ end
24
+ idx[:to] = @to if @to
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ module BasicBlock
2
+ class IndexXref
3
+ #
4
+ # @param [Boolean] also
5
+ # @param [Array<BasicBlock::TextElement>] primary
6
+ # @param [Array<BasicBlock::TextElement>] target
7
+ # @param [Hash] args
8
+ # @option args [Array<BasicBlock::TextElement>, nil] secondary
9
+ # @option args [Array<BasicBlock::TextElement>, nil] tertiary
10
+ #
11
+ def initialize(also:, primary:, target:, **args)
12
+ @also = also
13
+ @primary = primary
14
+ @target = target
15
+ @secondary = args[:secondary]
16
+ @tertiary = args[:tertiary]
17
+ end
18
+
19
+ #
20
+ # @param [Nokogiri::XML::Builder] builder
21
+ #
22
+ def to_xml(builder) # rubocop:disable Metrics/CyclomaticComplexity
23
+ builder.send "index-xref", also: @also do |b|
24
+ @primary.each { |p| p.to_xml b }
25
+ @secondary&.each { |s| s.to_xml b }
26
+ @tertiary&.each { |t| t.to_xml b }
27
+ @target.each { |t| t.to_xml b }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ module BasicBlock
2
+ class Note
3
+ #
4
+ # @param [String] id
5
+ # @param [Array<BasicBlock::Paragraph>] content
6
+ #
7
+ def initialize(id:, content:)
8
+ @id = id
9
+ @contain = content
10
+ end
11
+
12
+ #
13
+ # @param [Nokogiei::XMO::Builder] builder
14
+ #
15
+ def to_xml(builder)
16
+ builder.note id: @id do |b|
17
+ @content.each { |c| c.to_xm b }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module BasicBlock
2
+ class Paragraph
3
+ #
4
+ # @param [String] id
5
+ # @param [Array<BasicBlock::TextElement>] content
6
+ # @param [Array<BasicBlock::Note>] note
7
+ # @param [BasicBlock::Alignment, nil] align
8
+ #
9
+ def initialize(id:, content:, note:, align: nil)
10
+ @id = id
11
+ @content = content
12
+ @note = note
13
+ @align = align
14
+ end
15
+ end
16
+
17
+ #
18
+ # @param [Nokogiri::XML::Builder] builder
19
+ #
20
+ def to_xml(builder)
21
+ p = builder.p id: @id do |b|
22
+ @content.each { |c| c.to_xml b }
23
+ @note.each { |n| n.to_xml b }
24
+ end
25
+ p[:align] = @align if @align
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ module BasicBlock
2
+ class ParagraphWithFootnote
3
+ #
4
+ # @param [String] id
5
+ # @param [Hash] args
6
+ # @param [BasicBlock::Alignment, nil] align
7
+ # @param [Array<BasicBlock::TextElement, BasicBlock::Eref, BasicBlock::Stem,
8
+ # BasicBlock::Image, BasicBlock::Index, BasicBlock::IndexXref>] content
9
+ # @param [Array<RelatonIec::Note>] note
10
+ #
11
+ def initialize(id:, align: nil, content: [], note: [])
12
+ @id = id
13
+ @aligments = align
14
+ @content = content
15
+ @note = note
16
+ end
17
+
18
+ #
19
+ # @param [Nokogiri::XML::Builder] builder
20
+ #
21
+ def to_xml(builder)
22
+ elm = builder.p(@id) do |b|
23
+ @content.each { |te| te.to_xml b }
24
+ @note.each { |n| n.to_xml b }
25
+ end
26
+ elm[:align] = @align if @align
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,38 @@
1
+ module RelatonIec
2
+ def self.respond_to_missing?(method, _include_private)
3
+ method == "ReferenceFormat"
4
+ end
5
+
6
+ def self.method_missing(_method, *args)
7
+ ReferenceFormat.new *args
8
+ end
9
+
10
+ class ReferenceFormat
11
+ FORMATS = %w[external inline footnote callout].freeze
12
+
13
+ #
14
+ # @param [String] format
15
+ #
16
+ def initialize(format)
17
+ unless FORMATS.include? format
18
+ warn "[relaton-iec] WARNING: invalid reference format \"#{format}\""
19
+ warn "[relaton-iec] alloved reference formats are: #{FORMATS.join ', '}"
20
+ end
21
+ @format = format
22
+ end
23
+
24
+ #
25
+ # @return [String]
26
+ #
27
+ def to_s
28
+ @format
29
+ end
30
+
31
+ #
32
+ # @return [Sting] <description>
33
+ #
34
+ def inspect
35
+ to_s
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ module BasicBlock
2
+ class Stem
3
+ TYPES = %w[MathML AsciiMath].freeze
4
+
5
+ # @return [String]
6
+ attr_reader :type
7
+
8
+ #
9
+ # @param [String] type
10
+ # @param [Array<#to_xml>] content any element
11
+ #
12
+ def initialize(type:, content: [])
13
+ unless TYPES.include? type
14
+ warn "[relaton-iec] WARNING: invalud type \"#{type}\""
15
+ warn "[relaton-iec] allowed types are: #{TYPES.join ', '}"
16
+ end
17
+ @type = type
18
+ @content = content
19
+ end
20
+
21
+ #
22
+ # @param [Nokogiri::XML::Builder] builder
23
+ #
24
+ def to_xml(builder)
25
+ builder.stem(type) do |b|
26
+ content.each { |c| c.to_xml b }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,115 @@
1
+ module BasicBlock
2
+ class Table
3
+ #
4
+ # @param [String] id
5
+ # @param [Array<BasicBlock::Tr>] tbody
6
+ # @param [Array<BasicBlock::Paragraph>] note
7
+ # @param [Hash] args
8
+ # @option args [Boolean, nil] :unnumbered
9
+ # @option args [String, nil] :subsequence
10
+ # @option args [String, nil] :alt
11
+ # @option args [String, nil] :summary
12
+ # @option args [String, nil] :uri
13
+ # @option args [BasicBlock::TextElement, nil] :tname
14
+ # @option args [BasicBlock::Table::Tr, nil] :thead
15
+ # @option args [BasicBlock::TextElement, nil] :tfoot
16
+ # @option args [BasicBlock::Dl, nil] :dl
17
+ #
18
+ def initialize(id:, tbody:, note:, **args) # rubocop:disable Metrics/MethodLength
19
+ @id = id
20
+ @unnumbered = args[:unnumbered]
21
+ @subsequence = args[:subsequence]
22
+ @alt = args[:alt]
23
+ @summary = args[:summary]
24
+ @uri = args[:uri]
25
+ @tname = args[:tname]
26
+ @thead = args[:thead]
27
+ @tbody = tbody
28
+ @tfoot = args[:tfoot]
29
+ @note = note
30
+ @dl = args[:dl]
31
+ end
32
+
33
+ # @param [Nokogiri::XML::Builder] builder
34
+ def to_xml(builder) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
35
+ tab = builder.table id: @id do |b|
36
+ b.name { @tname.to_xml b } if @tname
37
+ b.thead { @thead.to_xml b } if @thead
38
+ @tbody.each { |tb| tb.to_xml b }
39
+ b.name { @tfoot.to_xml b } if @tfoot
40
+ @note.each { |n| b.note { n.to_xml b } }
41
+ @dl.to_xml b
42
+ end
43
+ tab[:unnumbered] = @unnumbered if @unnumbered
44
+ tab[:subsequence] = @subsequence if @subsequence
45
+ tab[:alt] = @alt if @alt
46
+ tab[:summary] = @summary if @summary
47
+ tab[:uri] = @uri if @uri
48
+ end
49
+
50
+ class Tr
51
+ # @param [Array<BasicBlock::Table::Td, BasicBlock::Table::Th>] content
52
+ def initialize(content)
53
+ @content = content
54
+ end
55
+
56
+ # @param [Nokogiri::XML::Builder] builder
57
+ def to_xml(builder)
58
+ builder.tr do |b|
59
+ @content.each { |c| c.to_xm b }
60
+ end
61
+ end
62
+ end
63
+
64
+ class TabCell
65
+ ALIGNS = %w[left right ceter].freeze
66
+ VALIGNS = %w[top middle bottom baseline].freeze
67
+
68
+ # @param [Array<BasicBlock::TextElement,
69
+ # BasicBlock::ParagraphWithFootnote>] content
70
+ # @param [Hssh] args
71
+ # @option args [String, nil] :colspan
72
+ # @option args [String, nil] :rowspan
73
+ # @option args [String, nil] :align
74
+ # @option args [String, nil] :valign
75
+ def initialize(content, **args) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
76
+ if args[:align] && !ALIGNS.include?(args[:align])
77
+ warn "[basic-block] WARNING: invalid table/tr/td align \"#{args[:align]}\""
78
+ warn "[basic-block] alloved aligns are: #{ALIGNS.join ', '}"
79
+ end
80
+ if args[:valign] && !VALIGNS.include?(args[:valign])
81
+ warn "[basic-block] WARNING: invalid table/tr/td valign \"#{args[:valign]}\""
82
+ warn "[basic-block] alloved valigns are: #{VALIGNS.join ', '}"
83
+ end
84
+ @content = content
85
+ @colspan = args[:colspan]
86
+ @rowspan = args[:rowspan]
87
+ @align = args[:align]
88
+ @valign = args[:valign]
89
+ end
90
+
91
+ # @param [Nokogiri::XML::Builder] builder
92
+ def to_xml(builder)
93
+ td = @content.each { |c| c.to_xml builder }
94
+ td[:colspan] = @colspan if @colspan
95
+ td[:rowspan] = @rowspan if @rowspan
96
+ td[:align] = @align if @align
97
+ td[:valign] = @valign if @valign
98
+ end
99
+ end
100
+
101
+ class Td < BasicBlock::Table::TabCell
102
+ # @param [Nokogiri::XML::Builder] builder
103
+ def to_xml(builder)
104
+ builder.th { super }
105
+ end
106
+ end
107
+
108
+ class Th < BasicBlock::Table::TabCell
109
+ # @param [Nokogiri::XML::Builder] builder
110
+ def to_xml(builder)
111
+ builder.td { super }
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,27 @@
1
+ module BasicBlock
2
+ class TextElement
3
+ TAGS = %w[em strong sub sup tt underline strike smallcap br hr keyword rp
4
+ rt ruby pagebreak bookmark].freeze
5
+
6
+ #
7
+ # @param [String] tag
8
+ # @param [Array<String, BasicBlock::TextElement, BasicBlock::Stem>,
9
+ # String] content
10
+ #
11
+ def initialize(tag:, content:)
12
+ unless TAGS.include? tag
13
+ warn "[basic-block] WARNING: invalid tag \"#{tag}\""
14
+ warn "[basic-block] allowed tags are: #{TAGS.join ', '}"
15
+ end
16
+ @tag = tag
17
+ @content = content
18
+ end
19
+
20
+ # @param [Nokogiri::XML::Builder]
21
+ def to_xml(builder)
22
+ builder.send @tag do |b|
23
+ @content.each { |c| c.is_a?(String) ? c : c.to_xml(b) }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -25,7 +25,7 @@ module RelatonIec
25
25
  def to_all_parts # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity
26
26
  parts = @array.reject { |h| h.part.nil? }
27
27
  hit = parts.min_by &:part
28
- return @array.first.fetch lang unless hit
28
+ return @array.first&.fetch unless hit
29
29
 
30
30
  bibitem = hit.fetch
31
31
  all_parts_item = bibitem.to_all_parts