Class: Graffle::StyledTextReader
- Defined in:
- lib/graffle/styled-text-reader.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#raw_text ⇒ Object
readonly
Returns the value of attribute raw_text.
Instance Method Summary collapse
- #as_lines ⇒ Object
-
#initialize(string) ⇒ StyledTextReader
constructor
A new instance of StyledTextReader.
- #is_rtf? ⇒ Boolean
- #without_rtf_header ⇒ Object
Constructor Details
#initialize(string) ⇒ StyledTextReader
Returns a new instance of StyledTextReader.
15 16 17 |
# File 'lib/graffle/styled-text-reader.rb', line 15 def initialize(string) @raw_text = string end |
Instance Attribute Details
#raw_text ⇒ Object (readonly)
Returns the value of attribute raw_text.
13 14 15 |
# File 'lib/graffle/styled-text-reader.rb', line 13 def raw_text @raw_text end |
Instance Method Details
#as_lines ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/graffle/styled-text-reader.rb', line 35 def as_lines lines = without_rtf_header return lines unless self.is_rtf? lines = lines.reject { |line| line.starts_with?("\\par") } lines.collect do |line| line = line.gsub(/^\\f\d\\fs\d\d \\cf\d /, '') line = line.gsub(/\}$/, '') line = line.gsub(/\\$/, '') end end |
#is_rtf? ⇒ Boolean
19 20 21 |
# File 'lib/graffle/styled-text-reader.rb', line 19 def is_rtf? @raw_text.starts_with?("{\\rtf") end |
#without_rtf_header ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/graffle/styled-text-reader.rb', line 23 def without_rtf_header lines = @raw_text.split("\n") return lines unless self.is_rtf? lines.each_with_index do | elt, index | unless elt.starts_with?("\\") or elt.starts_with?("{") index += 1 # skip past blank line return lines[index..-1] end end end |