Class: OoxmlParser::Spacing
- Inherits:
-
Object
- Object
- OoxmlParser::Spacing
- Defined in:
- lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/spacing.rb
Overview
Class to describe spacing
Instance Attribute Summary collapse
-
#after ⇒ Float
Spacing after paragraph.
-
#before ⇒ Float
Spacing before paragraph.
-
#line ⇒ Float
Spacing between lines.
-
#line_rule ⇒ String
Spacing line rule.
-
#line_spacing ⇒ LineSpacing
readonly
Line spacing data.
Instance Method Summary collapse
-
#==(other) ⇒ True, False
Compare this object to other.
-
#copy ⇒ Spacing
Method to copy object.
-
#fetch_from_valued_spacing(valued_spacing) ⇒ Spacing
Fetch data from ‘ParagraphSpacing` Which have values with parameters.
-
#initialize(before = nil, after = 0.35, line = nil, line_rule = nil) ⇒ Spacing
constructor
A new instance of Spacing.
-
#parse(node) ⇒ Nothing
Parse data for Spacing.
-
#round(count_of_digits = 1) ⇒ Spacing
Round value of spacing.
-
#to_s ⇒ String
Result of convert of object to string.
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
#after ⇒ Float
Returns 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 |
#before ⇒ Float
Returns 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 |
#line ⇒ Float
Returns 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_rule ⇒ String
Returns 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_spacing ⇒ LineSpacing (readonly)
Returns 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
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 |
#copy ⇒ Spacing
Method to copy object
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
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
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
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_s ⇒ String
Returns 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 |