Class: OoxmlParser::Spacing

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb

Overview

Class to describe spacing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(before = nil, after = 0.35, line = nil, line_rule = nil) ⇒ Spacing

Returns a new instance of Spacing.



20
21
22
23
24
25
# 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

Instance Attribute Details

#afterFloat

Returns Spacing after paragraph.

Returns:

  • (Float)

    Spacing after paragraph



12
13
14
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb', line 12

def after
  @after
end

#beforeFloat

Returns Spacing before paragraph.

Returns:

  • (Float)

    Spacing before paragraph



10
11
12
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb', line 10

def before
  @before
end

#lineFloat

Returns Spacing between lines.

Returns:

  • (Float)

    Spacing between lines



14
15
16
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb', line 14

def line
  @line
end

#line_ruleString

Returns Spacing line rule.

Returns:

  • (String)

    Spacing line rule



16
17
18
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb', line 16

def line_rule
  @line_rule
end

#line_spacingLineSpacing (readonly)

Returns line spacing data.

Returns:

  • (LineSpacing)

    line spacing data



18
19
20
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb', line 18

def line_spacing
  @line_spacing
end

Instance Method Details

#==(other) ⇒ True, False

Compare this object to other

Parameters:

  • other (Object)

    any other object

Returns:

  • (True, False)

    result of comparision



30
31
32
33
34
35
36
37
38
39
40
# 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

#copySpacing

Method to copy object

Returns:



54
55
56
# 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) ⇒ Spacing

Fetch data from ‘ParagraphSpacing` Which have values with parameters

Parameters:

Returns:



92
93
94
95
96
97
98
# 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) ⇒ Nothing

Parse data for Spacing

Parameters:

  • node (Nokogiri::XML:Element)

    with Spacing

Returns:

  • (Nothing)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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) ⇒ Spacing

Round value of spacing

Parameters:

  • count_of_digits (Integer) (defaults to: 1)

    how digits to left

Returns:



61
62
63
64
65
66
# 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_sString

Returns result of convert of object to string.

Returns:

  • (String)

    result of convert of object to string



43
44
45
46
47
48
49
50
# 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