Skip to content

Commit

Permalink
Refactor: Extract method: default_format_for
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Dec 16, 2016
1 parent 0c30a36 commit 0f049ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 2 additions & 6 deletions app/models/miq_report/formatting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ def get_available_formats(path, dt)

def get_default_format(path, dt)
col = path.split("-").last.to_sym
sfx = col.to_s.split("__").last
sfx = sfx.to_sym if sfx
MiqReportFormats::DEFAULTS_AND_OVERRIDES[:formats_by_suffix][sfx] ||
MiqReportFormats::DEFAULTS_AND_OVERRIDES[:formats_by_column][col] ||
MiqReportFormats::DEFAULTS_AND_OVERRIDES[:formats_by_sub_type][MiqReportFormats.sub_type(col)] ||
MiqReportFormats::DEFAULTS_AND_OVERRIDES[:formats_by_data_type][dt]
sfx = col.to_s.split("__").last.try(:to_sym)
MiqReportFormats.default_format_for(col, sfx, dt)
end
end

Expand Down
7 changes: 7 additions & 0 deletions lib/miq_report_formats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def self.available_formats_for(column, suffix, datatype)
end
end

def self.default_format_for(column, suffix, datatype)
DEFAULTS_AND_OVERRIDES[:formats_by_suffix][suffix] ||
DEFAULTS_AND_OVERRIDES[:formats_by_column][column] ||
DEFAULTS_AND_OVERRIDES[:formats_by_sub_type][MiqReportFormats.sub_type(column)] ||
DEFAULTS_AND_OVERRIDES[:formats_by_data_type][datatype]
end

def self.sub_type(column)
DEFAULTS_AND_OVERRIDES[:sub_types_by_column][column]
end
Expand Down

0 comments on commit 0f049ee

Please sign in to comment.