Class: SimpleTextExtract::Extract
- Inherits:
-
Object
- Object
- SimpleTextExtract::Extract
- Defined in:
- lib/simple_text_extract/extract.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename: nil, raw: nil, filepath: nil, tempfile: nil) ⇒ Extract
constructor
A new instance of Extract.
- #to_s ⇒ Object
Constructor Details
#initialize(filename: nil, raw: nil, filepath: nil, tempfile: nil) ⇒ Extract
Returns a new instance of Extract.
25 26 27 28 |
# File 'lib/simple_text_extract/extract.rb', line 25 def initialize(filename: nil, raw: nil, filepath: nil, tempfile: nil) @file = get_file(filename:, raw:, filepath:, tempfile:) @formatter = self.class.formatter(File.extname(file)) if file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
23 24 25 |
# File 'lib/simple_text_extract/extract.rb', line 23 def file @file end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
23 24 25 |
# File 'lib/simple_text_extract/extract.rb', line 23 def formatter @formatter end |
Class Method Details
.formatter(path) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/simple_text_extract/extract.rb', line 4 def self.formatter(path) case path when /.zip$/i :zip when /(.txt$|.csv$)/i :plain when /.pdf$/i :pdf when /.docx$/i :docx when /.doc$/i :doc when /.xlsx$/i :xlsx when /.xls$/i :xls end end |
Instance Method Details
#to_s ⇒ Object
30 31 32 |
# File 'lib/simple_text_extract/extract.rb', line 30 def to_s @to_s ||= extract.to_s.scrub.gsub(/[^\S\n]+/, " ").gsub(/\s?\n\s+/, "\n").strip end |