Class: Panda::Core::FileParser
- Inherits:
-
Object
- Object
- Panda::Core::FileParser
show all
- Defined in:
- app/services/panda/core/file_parser.rb
Defined Under Namespace
Classes: UnsupportedFormatError
Constant Summary
collapse
- SUPPORTED_EXTENSIONS =
%w[.csv .tsv .xlsx].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(filename, content) ⇒ FileParser
Returns a new instance of FileParser.
13
14
15
16
17
|
# File 'app/services/panda/core/file_parser.rb', line 13
def initialize(filename, content)
@filename = filename
@content = content
@extension = File.extname(filename).downcase
end
|
Class Method Details
.supported?(filename) ⇒ Boolean
27
28
29
30
|
# File 'app/services/panda/core/file_parser.rb', line 27
def self.supported?(filename)
ext = File.extname(filename).downcase
SUPPORTED_EXTENSIONS.include?(ext)
end
|
.xls?(filename) ⇒ Boolean
32
33
34
|
# File 'app/services/panda/core/file_parser.rb', line 32
def self.xls?(filename)
File.extname(filename).downcase == ".xls"
end
|
Instance Method Details
19
20
21
|
# File 'app/services/panda/core/file_parser.rb', line 19
def
@headers ||= parse.first
end
|
#rows ⇒ Object
23
24
25
|
# File 'app/services/panda/core/file_parser.rb', line 23
def rows
@rows ||= parse.last
end
|