Module: Xvert

Defined in:
lib/xvert.rb,
lib/xvert/cli.rb,
lib/xvert/version.rb

Defined Under Namespace

Classes: CLI, UnsupportedFormatError

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.convert(text, from:, to:) ⇒ Object



17
18
19
20
# File 'lib/xvert.rb', line 17

def convert(text, from:, to:)
  object = to_object(text, format: from)
  to_text(object, format: to)
end

.to_object(text, format:) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/xvert.rb', line 22

def to_object(text, format:)
  case format
  when :json then json_to_object(text)
  when :yaml then yaml_to_object(text)
  when :toml then toml_to_object(text)
  else raise UnsupportedFormatError, format
  end
end

.to_text(object, format:) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/xvert.rb', line 31

def to_text(object, format:)
  case format
  when :json then object_to_json(object)
  when :yaml then object_to_yaml(object)
  when :toml then object_to_toml(object)
  else raise UnsupportedFormatError, format
  end
end