Class: OoxmlParser::Indents
- Inherits:
-
Object
- Object
- OoxmlParser::Indents
- Defined in:
- lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb
Instance Attribute Summary collapse
-
#first_line_indent ⇒ Object
Returns the value of attribute first_line_indent.
-
#hanging_indent ⇒ Object
Returns the value of attribute hanging_indent.
-
#left_indent ⇒ Object
Returns the value of attribute left_indent.
-
#right_indent ⇒ Object
Returns the value of attribute right_indent.
Class Method Summary collapse
-
.parse(node) ⇒ Indents
Parse Indents.
-
.parse_indents_hash(hash) ⇒ Indents
Parse hash with indents.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#copy ⇒ Indents
Indents.
- #equal_with_round(other, delta = 0.02) ⇒ Object
-
#increase_indent_by_button(count = 1) ⇒ Object
Increases indent, depending on clicks to “increase indent” button in canvas.
-
#initialize(first_line_indent = 0.0, left_indent = 0.0, right_indent = 0.0, hanging_indent = nil) ⇒ Indents
constructor
A new instance of Indents.
- #round(digits_after_dot = 0) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(first_line_indent = 0.0, left_indent = 0.0, right_indent = 0.0, hanging_indent = nil) ⇒ Indents
Returns a new instance of Indents.
5 6 7 8 9 10 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 5 def initialize(first_line_indent = 0.0, left_indent = 0.0, right_indent = 0.0, hanging_indent = nil) @first_line_indent = first_line_indent @left_indent = left_indent @right_indent = right_indent @hanging_indent = hanging_indent end |
Instance Attribute Details
#first_line_indent ⇒ Object
Returns the value of attribute first_line_indent.
3 4 5 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 3 def first_line_indent @first_line_indent end |
#hanging_indent ⇒ Object
Returns the value of attribute hanging_indent.
3 4 5 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 3 def hanging_indent @hanging_indent end |
#left_indent ⇒ Object
Returns the value of attribute left_indent.
3 4 5 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 3 def left_indent @left_indent end |
#right_indent ⇒ Object
Returns the value of attribute right_indent.
3 4 5 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 3 def right_indent @right_indent end |
Class Method Details
.parse(node) ⇒ Indents
Parse Indents
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 70 def self.parse(node) indents = Indents.new unless node.attribute('firstLine').nil? indents.first_line_indent = (node.attribute('firstLine').value.to_f / 566.9).round(2) end unless node.attribute('left').nil? indents.left_indent = (node.attribute('left').value.to_f / 566.9).round(2) end unless node.attribute('right').nil? indents.right_indent = (node.attribute('right').value.to_f / 566.9).round(2) end unless node.attribute('hanging').nil? indents.hanging_indent = (node.attribute('hanging').value.to_f / 566.9).round(2) end indents end |
.parse_indents_hash(hash) ⇒ Indents
Parse hash with indents
45 46 47 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 45 def self.parse_indents_hash(hash) Indents.new(hash['first_line_indent'], hash['left_indent'], hash['right_indent'], hash['hanging_indent']) end |
Instance Method Details
#==(other) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 12 def ==(other) if self.class != NilClass && other.class != NilClass if @first_line_indent.to_f == other.first_line_indent.to_f && @left_indent.to_f.round(2) == other.left_indent.to_f.round(2) && @right_indent.to_f.round(1) == other.right_indent.to_f.round(1) return true if @hanging_indent.nil? || other.hanging_indent.nil? @hanging_indent.to_f == other.hanging_indent.to_f else false end else is_a?(NilClass) && other.is_a?(NilClass) end end |
#copy ⇒ Indents
Returns Indents.
56 57 58 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 56 def copy Indents.new(@first_line_indent, @left_indent, @right_indent, @hanging_indent) end |
#equal_with_round(other, delta = 0.02) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 27 def equal_with_round(other, delta = 0.02) if is_a?(NilClass) && other.is_a?(NilClass) true else @first_line_indent.to_f.round(2) == other.first_line_indent.to_f.round(2) && @left_indent.to_f.round(2) == other.left_indent.to_f.round(2) && @right_indent.to_f.round(2) == other.right_indent.to_f.round(2) && (@hanging_indent.to_f.round(2) - other.hanging_indent.to_f.round(2)).to_f.abs < delta end end |
#increase_indent_by_button(count = 1) ⇒ Object
Increases indent, depending on clicks to “increase indent” button in canvas
51 52 53 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 51 def (count = 1) count.times { @left_indent += 1.25 } end |
#round(digits_after_dot = 0) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 60 def round(digits_after_dot = 0) [:first_line_indent, :left_indent, :right_indent, :hanging_indent].each do |ind| send("#{ind}=", send(ind).round(digits_after_dot)) unless send(ind).nil? end self end |
#to_s ⇒ Object
38 39 40 41 |
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb', line 38 def to_s "first line indent: #{@first_line_indent}, left indent: #{@left_indent}, right indent: #{@right_indent}, hanging indent: #{@hanging_indent}" end |