Class: Idcf::Cli::Lib::Convert::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/idcf/cli/lib/convert/helper.rb

Overview

format helper

Constant Summary collapse

FILTER_OPTION =
%i[json_path fields].freeze

Instance Method Summary collapse

Instance Method Details

#filter(data, o, table_flag) ⇒ Object

data convert

Parameters:

  • data (Hash)
  • o (Hash)

    format

  • table_flag (Boolean)

Returns:

  • Hash



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/idcf/cli/lib/convert/helper.rb', line 52

def filter(data, o, table_flag)
  result = data.deep_dup
  FILTER_OPTION.each do |k|
    next if o[k].nil? || o[k].empty?
    fo = {
      table_flag: table_flag
    }
    result = cls_load("Filter::#{k.to_s.classify}Filter").new(**fo).filter(result, o[k])
  end
  result
end

#filter_target?(o) ⇒ Boolean

is filter target

Parameters:

  • o (Hash)

Returns:

  • (Boolean)

    Boolean



26
27
28
29
30
31
# File 'lib/idcf/cli/lib/convert/helper.rb', line 26

def filter_target?(o)
  FILTER_OPTION.each do |k|
    return true if !o[k].nil? && !o[k].empty?
  end
  false
end

#format(data, f) ⇒ Object

data convert

Parameters:

  • data (Hash)
  • f (String)

    format

Returns:

  • String



19
20
21
# File 'lib/idcf/cli/lib/convert/helper.rb', line 19

def format(data, f)
  cls_load("Formatter::#{f.classify}Format").new.format(data)
end

#only_filter_fields?(o) ⇒ Boolean

only filter

Parameters:

  • o (Hash)

Returns:

  • (Boolean)

    Boolean



37
38
39
40
41
42
43
44
# File 'lib/idcf/cli/lib/convert/helper.rb', line 37

def only_filter_fields?(o)
  return false if o[:fields].nil?
  list = []
  FILTER_OPTION.each do |k|
    list << k if o[k].present?
  end
  list.count == 1
end