Class: OoxmlParser::Spacing
- Inherits:
-
Object
- Object
- OoxmlParser::Spacing
- Defined in:
- lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb
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.
Class Method Summary collapse
- .default_spacing_canvas(line_spacing = 1.15) ⇒ Object
-
.parse_spacing_rule(node) ⇒ Symbol
Parse spacing rule.
-
.parse_spacing_value(node) ⇒ Float
Parse values of spacing number.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #copy ⇒ Object
-
#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) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(before = nil, after = 0.35, line = nil, line_rule = nil) ⇒ Spacing
Returns a new instance of Spacing.
16 17 18 19 20 21 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 16 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.
10 11 12 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 10 def after @after end |
#before ⇒ Float
Returns Spacing before paragraph.
8 9 10 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 8 def before @before end |
#line ⇒ Float
Returns Spacing between lines.
12 13 14 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 12 def line @line end |
#line_rule ⇒ String
Returns Spacing line rule.
14 15 16 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 14 def line_rule @line_rule end |
Class Method Details
.default_spacing_canvas(line_spacing = 1.15) ⇒ Object
55 56 57 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 55 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
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 102 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
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 86 def self.parse_spacing_value(node) node.xpath('*').each do |spacing_node_child| case spacing_node_child.name when 'spcPct' return (spacing_node_child.attribute('val').value.to_f / 100_000.0).round(2) when 'spcPts' return (spacing_node_child.attribute('val').value.to_f / 2_834.0).round(2) else return (spacing_node_child.attribute('val').value.to_f / 1_000.0).round(2) end end end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 23 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.to_f.round(2) == other.before.to_f.round(2) && @after.to_f.round(2) == other.after.to_f.round(2) && @line.to_f.round(2) == other.line.to_f.round(2) && @line_rule.to_s == other.line_rule.to_s return true else return false end end end |
#copy ⇒ Object
51 52 53 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 51 def copy Spacing.new(@before, @after, @line, @line_rule) end |
#parse(node) ⇒ Nothing
Parse data for Spacing
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 69 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
59 60 61 62 63 64 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 59 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 ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb', line 42 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 |