Class: FlatKit::Format

Inherits:
Object
  • Object
show all
Extended by:
DescendantTracker
Defined in:
lib/flat_kit/format.rb

Direct Known Subclasses

Jsonl::Format, Xsv::Format

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DescendantTracker

children, find_child, inherited

Class Method Details

.for(path) ⇒ Object



13
14
15
# File 'lib/flat_kit/format.rb', line 13

def self.for(path)
  find_child(:handles?, path.to_s)
end

.for_with_fallback(path:, fallback: "auto") ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/flat_kit/format.rb', line 17

def self.for_with_fallback(path:, fallback: "auto")
  # test by path
  format = ::FlatKit::Format.for(path)
  return format unless format.nil?

  # now try the fallback
  format = ::FlatKit::Format.for(fallback)
  return format
end

.for_with_fallback!(path:, fallback: "auto") ⇒ Object



27
28
29
30
31
32
# File 'lib/flat_kit/format.rb', line 27

def self.for_with_fallback!(path:, fallback: "auto")
  format = for_with_fallback(path: path, fallback: fallback)
  raise ::FlatKit::Error::UnknownFormat, "Unable to figure out format for '#{path}' with fallback '#{fallback}'" if format.nil?

  return format
end

.format_nameObject

Raises:

  • (NotImplementedError)


5
6
7
# File 'lib/flat_kit/format.rb', line 5

def self.format_name
  raise NotImplementedError, "#{self.class} must implemente #{self.class}.format_name"
end

Instance Method Details

#format_nameObject



9
10
11
# File 'lib/flat_kit/format.rb', line 9

def format_name
  self.class.format_name
end