class OoxmlParser::Spacing

Class to describe spacing

Attributes

after[RW]

@return [Float] Spacing after paragraph

before[RW]

@return [Float] Spacing before paragraph

line[RW]

@return [Float] Spacing between lines

line_rule[RW]

@return [String] Spacing line rule

line_spacing[R]

@return [LineSpacing] line spacing data

Public Class Methods

new(before = nil, after = 0.35, line = nil, line_rule = nil) click to toggle source
# File lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb, line 20
def initialize(before = nil, after = 0.35, line = nil, line_rule = nil)
  @before = before
  @after = after
  @line = line
  @line_rule = line_rule
end

Public Instance Methods

==(other) click to toggle source

Compare this object to other @param other [Object] any other object @return [True, False] result of comparision

# File lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb, line 30
def ==(other)
  self.line_rule = :at_least if line_rule == 'atLeast'
  self.line_rule = :multiple if line_rule == :auto
  other.line_rule = :multiple if other.line_rule == :auto
  self.line_rule = line_rule.to_sym if line_rule.instance_of?(String)

  @before == other.before &&
    @after == other.after &&
    @line == other.line &&
    @line_rule.to_s == other.line_rule.to_s
end
copy() click to toggle source

Method to copy object @return [Spacing] copied object

# File lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb, line 54
def copy
  Spacing.new(@before, @after, @line, @line_rule)
end
fetch_from_valued_spacing(valued_spacing) click to toggle source

Fetch data from ‘ParagraphSpacing` Which have values with parameters @param valued_spacing [ParagraphSpacing] spacing to get params @return [Spacing]

# File lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb, line 92
def fetch_from_valued_spacing(valued_spacing)
  @before = valued_spacing.before.to_unit(:centimeter).value if valued_spacing.before
  @after = valued_spacing.after.to_unit(:centimeter).value if valued_spacing.after
  @line = valued_spacing.line.to_unit(:centimeter).value if valued_spacing.line
  @line_rule = valued_spacing.line_rule if valued_spacing.line_rule
  self
end
parse(node) click to toggle source

Parse data for Spacing @param [Nokogiri::XML:Element] node with Spacing @return [Nothing]

# File lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb, line 71
def parse(node)
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'lnSpc'
      @line_spacing = SpacingValuedChild.new(parent: self).parse(node_child)
      self.line = @line_spacing.to_ooxml_size
      self.line_rule = @line_spacing.rule
    when 'spcBef'
      @spacing_before = SpacingValuedChild.new(parent: self).parse(node_child)
      self.before = @spacing_before.to_ooxml_size
    when 'spcAft'
      @spacing_after = SpacingValuedChild.new(parent: self).parse(node_child)
      self.after = @spacing_after.to_ooxml_size
    end
  end
end
round(count_of_digits = 1) click to toggle source

Round value of spacing @param count_of_digits [Integer] how digits to left @return [Spacing] result of round

# File lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb, line 61
def round(count_of_digits = 1)
  before = @before.to_f.round(count_of_digits)
  after = @after.to_f.round(count_of_digits)
  line = @line.to_f.round(count_of_digits)
  Spacing.new(before, after, line, @line_rule)
end
to_s() click to toggle source

@return [String] result of convert of object to string

# File lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb, line 43
def to_s
  result_string = ''
  variables = instance_variables
  variables.each do |current_variable|
    result_string += "#{current_variable.to_s.sub('@', '')}: #{instance_variable_get(current_variable)}\n"
  end
  result_string
end