Class: PartGroup
- Inherits:
-
Array
- Object
- Array
- PartGroup
- Defined in:
- lib/rmsgen/part_group.rb
Constant Summary collapse
- DELIMETER =
"\n\n"
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #assign_parts! ⇒ Object
-
#initialize(text) ⇒ PartGroup
constructor
A new instance of PartGroup.
Constructor Details
#initialize(text) ⇒ PartGroup
Returns a new instance of PartGroup.
6 7 8 9 |
# File 'lib/rmsgen/part_group.rb', line 6 def initialize(text) @text = text assign_parts! end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
2 3 4 |
# File 'lib/rmsgen/part_group.rb', line 2 def text @text end |
Instance Method Details
#assign_parts! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rmsgen/part_group.rb', line 11 def assign_parts! if @text.match /\r\n\r\n/ @text.gsub!(/\r\n\r\n/, "\n\n") @text.gsub!(/\r\n/, " ") @text.gsub!(/\n\n\n\n/, "") else @text.gsub!(/\n\n/, '[newline]') @text.gsub!(/\n/, ' ') @text.gsub!('[newline]', "\n\n") end @text.split(DELIMETER).delete_if(&:empty?).each { |p| self << p } end |