Class: Eco::CliDefault::Input

Inherits:
API::Common::Loaders::CliConfig show all
Defined in:
lib/eco/cli_default/input.rb

Constant Summary collapse

FORMATS =
{
  csv:  {
    option:  ["-csv"],
    extname: [".csv", ".txt"]
  },
  xml:  {
    option:  ["-xml"],
    extname: [".xml"]
  },
  xls:  {
    option:  ["-xls", "-xlsx", "-excel"],
    extname: [".xls", ".xlsx", ".xlsm"]
  },
  json: {
    option:  ["-json"],
    extname: [".json"]
  }
}.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from API::Common::Loaders::CliConfig

config

Methods inherited from API::Common::Loaders::Config

active_enviro, cli, config, config_block

Methods included from API::Common::ClassHelpers

#class_resolver, #descendants, #descendants?, #inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #resolve_class, #to_constant

Methods included from Language::Methods::DelegateMissing

#delegate_missing_to, #method_missing, #respond_to_missing?

Class Attribute Details

.optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/eco/cli_default/input.rb', line 22

def options
  @options
end

.sessionObject (readonly)

Returns the value of attribute session.



22
23
24
# File 'lib/eco/cli_default/input.rb', line 22

def session
  @session
end

Class Method Details

.encodingObject



24
25
26
# File 'lib/eco/cli_default/input.rb', line 24

def encoding
  options.dig(:input, :file, :encoding)
end

.format_by_cliObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eco/cli_default/input.rb', line 28

def format_by_cli
  FORMATS.reduce(nil) do |matched, (frm, selectors)|
    next matched if matched

    used = selectors[:option].reduce(false) do |us, option|
      SCR.get_arg(option) || us
    end

    next frm if used
  end
end

.format_by_ext(ext) ⇒ Object



40
41
42
43
44
45
# File 'lib/eco/cli_default/input.rb', line 40

def format_by_ext(ext)
  FORMATS.reduce(nil) do |matched, (frm, selectors)|
    next matched if matched
    next frm     if selectors[:extname].any? {|e| ext == e}
  end
end