Class: Coradoc::Element::Title
- Defined in:
- lib/coradoc/element/title.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
(also: #text)
Returns the value of attribute content.
-
#id ⇒ Object
Returns the value of attribute id.
-
#level_int ⇒ Object
Returns the value of attribute level_int.
-
#line_break ⇒ Object
Returns the value of attribute line_break.
-
#style ⇒ Object
Returns the value of attribute style.
Instance Method Summary collapse
-
#initialize(content, level, options = {}) ⇒ Title
constructor
A new instance of Title.
- #level ⇒ Object
- #level_str ⇒ Object
- #style_str ⇒ Object
- #to_adoc ⇒ Object
Methods inherited from Base
#children_accessors, children_accessors, declare_children, #simplify_block_content, visit, #visit
Constructor Details
#initialize(content, level, options = {}) ⇒ Title
Returns a new instance of Title.
8 9 10 11 12 13 14 15 16 |
# File 'lib/coradoc/element/title.rb', line 8 def initialize(content, level, = {}) @level_int = level # @level_int = level.length - 1 if level.is_a?(String) @content = content @id = .fetch(:id, nil) @anchor = @id.nil? ? nil : Inline::Anchor.new(@id) @line_break = .fetch(:line_break, "") @style = .fetch(:style, nil) end |
Instance Attribute Details
#content ⇒ Object Also known as: text
Returns the value of attribute content.
4 5 6 |
# File 'lib/coradoc/element/title.rb', line 4 def content @content end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/coradoc/element/title.rb', line 4 def id @id end |
#level_int ⇒ Object
Returns the value of attribute level_int.
4 5 6 |
# File 'lib/coradoc/element/title.rb', line 4 def level_int @level_int end |
#line_break ⇒ Object
Returns the value of attribute line_break.
4 5 6 |
# File 'lib/coradoc/element/title.rb', line 4 def line_break @line_break end |
#style ⇒ Object
Returns the value of attribute style.
4 5 6 |
# File 'lib/coradoc/element/title.rb', line 4 def style @style end |
Instance Method Details
#level ⇒ Object
18 19 20 |
# File 'lib/coradoc/element/title.rb', line 18 def level @level ||= level_from_string end |
#level_str ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/coradoc/element/title.rb', line 31 def level_str if @level_int <= 5 "=" * (@level_int + 1) else "======" end end |
#style_str ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/coradoc/element/title.rb', line 39 def style_str style = [@style] style << "level=#{@level_int}" if @level_int > 5 style = style.compact.join(",") "[#{style}]\n" unless style.empty? end |
#to_adoc ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/coradoc/element/title.rb', line 22 def to_adoc anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n" content = Coradoc.strip_unicode(Coradoc::Generator.gen_adoc(@content)) <<~HERE #{anchor}#{style_str}#{level_str} #{content} HERE end |