Module: Grayskull::Formats
- Defined in:
- lib/grayskull/formats.rb,
lib/grayskull/formats/json_handler.rb,
lib/grayskull/formats/yaml_handler.rb
Overview
The Formats module contains handlers for all the supported formats and methods for format detection.
Defined Under Namespace
Classes: JSONHandler, YAMLHandler
Constant Summary collapse
- FILENAME_PATTERN =
Regular Expression to get file extension.
/(.+)\.([^\/\.]+)/
Class Method Summary collapse
-
.detect_format(filename) ⇒ Object
Gets the file extension of the given file and returns the file format.
Class Method Details
.detect_format(filename) ⇒ Object
Gets the file extension of the given file and returns the file format.
Raises an exception if file is not of a valid type.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/grayskull/formats.rb', line 16 def self.detect_format(filename) matches = FILENAME_PATTERN.match(filename.downcase).to_a if matches ext = matches[2] case ext when 'json' return 'json' when 'yml' return 'yaml' else raise TypeError, "Not a supported file format: " + ext end else raise LoadError, "Not a valid filename: " + filename end end |