Class: OoxmlParser::Spacing

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

Instance Attribute Summary collapse

Class Method 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.



15
16
17
18
19
20
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 15

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



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

def after
  @after
end

#beforeFloat

Returns Spacing before paragraph.

Returns:

  • (Float)

    Spacing before paragraph



7
8
9
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 7

def before
  @before
end

#lineFloat

Returns Spacing between lines.

Returns:

  • (Float)

    Spacing between lines



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

def line
  @line
end

#line_ruleString

Returns Spacing line rule.

Returns:

  • (String)

    Spacing line rule



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

def line_rule
  @line_rule
end

Class Method Details

.default_spacing_canvas(line_spacing = 1.15) ⇒ Object



56
57
58
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 56

def self.default_spacing_canvas(line_spacing = 1.15)
  Spacing.new(0.0, 0.35277777777777775, line_spacing)
end

.parse_spacing_rule(node) ⇒ Symbol

Parse spacing rule

Parameters:

  • node (Nokogiri::XML:Element)

    with Spacing

Returns:

  • (Symbol)

    type of spacing rule



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 101

def self.parse_spacing_rule(node)
  node.xpath('*').each do |spacing_node_child|
    case spacing_node_child.name
    when 'spcPct'
      return :multiple
    when 'spcPts'
      return :exact
    else
      return :at_least
    end
  end
end

.parse_spacing_value(node) ⇒ Float

Parse values of spacing number

Parameters:

  • node (Nokogiri::XML:Element)

    with Spacing

Returns:

  • (Float)

    value of spacing number



87
88
89
90
91
92
93
94
95
96
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 87

def self.parse_spacing_value(node)
  node.xpath('*').each do |spacing_node_child|
    case spacing_node_child.name
    when 'spcPct'
      return OoxmlSize.new(spacing_node_child.attribute('val').value.to_f, :one_1000th_percent)
    when 'spcPts'
      return OoxmlSize.new(spacing_node_child.attribute('val').value.to_f, :spacing_point)
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 22

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
  if self.class == NilClass || other.class == NilClass
    return true if self.class == NilClass && other.class == NilClass
    return false
  else
    self.line_rule = line_rule.to_sym if line_rule.instance_of?(String)

    if @before == other.before &&
       @after == other.after &&
       @line == other.line &&
       @line_rule.to_s == other.line_rule.to_s
      return true
    else
      return false
    end
  end
end

#copyObject



52
53
54
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 52

def copy
  Spacing.new(@before, @after, @line, @line_rule)
end

#parse(node) ⇒ Nothing

Parse data for Spacing

Parameters:

  • node (Nokogiri::XML:Element)

    with Spacing

Returns:

  • (Nothing)


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 70

def parse(node)
  node.xpath('*').each do |spacing_node_child|
    case spacing_node_child.name
    when 'lnSpc'
      self.line = Spacing.parse_spacing_value(spacing_node_child)
      self.line_rule = Spacing.parse_spacing_rule(spacing_node_child)
    when 'spcBef'
      self.before = Spacing.parse_spacing_value(spacing_node_child)
    when 'spcAft'
      self.after = Spacing.parse_spacing_value(spacing_node_child)
    end
  end
end

#round(count_of_digits = 1) ⇒ Object



60
61
62
63
64
65
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 60

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_sObject



43
44
45
46
47
48
49
50
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_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).to_s + "\n"
  end
  result_string
end