Module: ReportUtils
- Defined in:
- backend/app/lib/reports/report_utils.rb
Class Method Summary collapse
-
.fix_boolean_fields(row, fields) ⇒ Object
-
.fix_container_indicator(row, container_num = 1) ⇒ Object
-
.fix_decimal_format(record, fields) ⇒ Object
-
.fix_extent_format(row) ⇒ Object
-
.fix_id(row) ⇒ Object
-
.fix_identifier_format(row, field_name = :identifier) ⇒ Object
-
.get_enum_values(row, fields) ⇒ Object
-
.get_location_coordinate(row) ⇒ Object
-
.local_times(row, fields) ⇒ Object
-
.normalize_label(label) ⇒ Object
Class Method Details
.fix_boolean_fields(row, fields) ⇒ Object
13 14 15 16 17 18 |
# File 'backend/app/lib/reports/report_utils.rb', line 13 def self.fix_boolean_fields(row, fields) fields.each do |field| next if row[field] == nil row[field] = row[field] == 0 || row[field] == '0' ? 'No' : 'Yes' end end |
.fix_container_indicator(row, container_num = 1) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'backend/app/lib/reports/report_utils.rb', line 42 def self.fix_container_indicator(row, container_num = 1) if container_num == 1 type_field = :type indicator_field = :indicator field = :container elsif container_num == 2 type_field = :type_2 indicator_field = :indicator_2 field = :container_2 else type_field = :type_3 indicator_field = :indicator_3 field = :container_3 end row[field] = [row[type_field], row[indicator_field]].compact.join(' ') row.delete(type_field) row.delete(indicator_field) row[field] = nil if row[field] == '' end |
.fix_decimal_format(record, fields) ⇒ Object
36 37 38 39 40 |
# File 'backend/app/lib/reports/report_utils.rb', line 36 def self.fix_decimal_format(record, fields) fields.each do |field| record[field] = format('%.2f', record[field].to_s) if record[field] end end |
.fix_extent_format(row) ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'backend/app/lib/reports/report_utils.rb', line 2 def self.fix_extent_format(row) row[:extent_number] = 0.0 unless row[:extent_number] begin row[:extent] = "#{format('%.2f', row[:extent_number].to_s)} #{row[:extent_type]}" rescue ArgumentError => e row[:extent] = "#{row[:extent_number]} #{row[:extent_type]}" end row.delete(:extent_type) row.delete(:extent_number) end |
.fix_id(row) ⇒ Object
118 119 120 121 |
# File 'backend/app/lib/reports/report_utils.rb', line 118 def self.fix_id(row) row[:record_id] = normalize_label(row[:linked_record_type].to_s) + '_' + row[:record_id].to_s row.delete(:linked_record_type) end |
.fix_identifier_format(row, field_name = :identifier) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'backend/app/lib/reports/report_utils.rb', line 20 def self.fix_identifier_format(row, field_name = :identifier) if row[field_name] identifiers = row[field_name].split(',,,') else identifiers = [] end result = [] identifiers.each do |identifier| result.push(ASUtils.json_parse(identifier).compact.join('.')) end row[field_name] = result.join(', ') end |
.get_enum_values(row, fields) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'backend/app/lib/reports/report_utils.rb', line 63 def self.get_enum_values(row, fields) fields.each do |field| next unless row[field] if row[field].is_a?(Integer) values = [row[field]] else values = row[field].split(', ') end results = [] values.each do |value| begin enum_value = EnumerationValue.get_or_die(value) enumeration = enum_value.enumeration.name results.push(I18n.t("enumerations.#{enumeration}.#{enum_value.value}", :default => enum_value.value)) rescue Exception => e results.push("Missing enum value: #{value}") end end row[field] = results.join(', ') end end |
.get_location_coordinate(row) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'backend/app/lib/reports/report_utils.rb', line 89 def self.get_location_coordinate(row) coor_1 = [row[:coordinate_1_label], row[:coordinate_1_indicator]].compact.join(' ') coor_2 = [row[:coordinate_2_label], row[:coordinate_2_indicator]].compact.join(' ') coor_3 = [row[:coordinate_3_label], row[:coordinate_3_indicator]].compact.join(' ') coordinates = [] coordinates.push(coor_1) if coor_1 != '' coordinates.push(coor_2) if coor_2 != '' coordinates.push(coor_2) if coor_2 != '' row[:location_in_room] = [coor_1, coor_2, coor_3].compact.join(', ') row.delete(:coordinate_1_label) row.delete(:coordinate_1_indicator) row.delete(:coordinate_2_label) row.delete(:coordinate_2_indicator) row.delete(:coordinate_3_label) row.delete(:coordinate_3_indicator) end |
.local_times(row, fields) ⇒ Object
106 107 108 109 110 111 112 |
# File 'backend/app/lib/reports/report_utils.rb', line 106 def self.local_times(row, fields) fields.each do |field| next unless row[field] row[field] = row[field].localtime.strftime( '%Y-%m-%d %H:%M:%S') end end |
.normalize_label(label) ⇒ Object
114 115 116 |
# File 'backend/app/lib/reports/report_utils.rb', line 114 def self.normalize_label(label) label.strip.downcase.gsub(/[^a-z0-9]+/, '_').gsub(/_+$/, '') end |