Class: RubyDocx::Convertor::Html::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_docx/convertors/elements/html/base.rb

Direct Known Subclasses

Br, Header, Hyperlink, Paragraph, Span, Table, Td, Tr

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, css) ⇒ Base

Returns a new instance of Base.



4
5
6
7
# File 'lib/ruby_docx/convertors/elements/html/base.rb', line 4

def initialize(tag, css)
  @tag = tag
  @css = css
end

Instance Attribute Details

#cssObject (readonly)

Returns the value of attribute css.



3
4
5
# File 'lib/ruby_docx/convertors/elements/html/base.rb', line 3

def css
  @css
end

#tagObject (readonly)

Returns the value of attribute tag.



3
4
5
# File 'lib/ruby_docx/convertors/elements/html/base.rb', line 3

def tag
  @tag
end

Instance Method Details

#buildObject



9
10
11
12
13
# File 'lib/ruby_docx/convertors/elements/html/base.rb', line 9

def build
  node = convert
  node.add_styles(styles) if styles.present?
  node
end

#convertObject



15
16
17
# File 'lib/ruby_docx/convertors/elements/html/base.rb', line 15

def convert
  RubyDocx::InextensibleBlock.new
end

#stylesObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_docx/convertors/elements/html/base.rb', line 19

def styles
  @styles = {}
  eval_styles.reverse.each do |row|
    prop, val = row.split(':', 2).map(&:strip)
    unless @styles.has_key? prop
      @styles[prop] = val.sub /;$/, ''
    end
  end
  @styles
end