Class: Idcf::Cli::Lib::Convert::Helper
- Inherits:
-
Object
- Object
- Idcf::Cli::Lib::Convert::Helper
- 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
-
#filter(data, o, table_flag) ⇒ Object
data convert.
-
#filter_target?(o) ⇒ Boolean
is filter target.
-
#format(data, f) ⇒ Object
data convert.
-
#only_filter_fields?(o) ⇒ Boolean
only filter.
Instance Method Details
#filter(data, o, table_flag) ⇒ Object
data convert
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
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
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
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 |