Module: ODFReport::Nested
Instance Method Summary collapse
- #get_collection_from_item(item, collection_field) ⇒ Object
- #get_fields_with_values(data_item) ⇒ Object
- #replace_values!(new_section, data_item) ⇒ Object
Instance Method Details
#get_collection_from_item(item, collection_field) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/odf-report/nested.rb', line 33 def get_collection_from_item(item, collection_field) if collection_field.is_a?(Array) tmp = item.dup collection_field.each do |f| if f.is_a?(Hash) tmp = tmp.send(f.keys[0], f.values[0]) else tmp = tmp.send(f) end end collection = tmp elsif collection_field.is_a?(Hash) collection = item.send(collection_field.keys[0], collection_field.values[0]) else collection = item.send(collection_field) end return collection end |
#get_fields_with_values(data_item) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/odf-report/nested.rb', line 9 def get_fields_with_values(data_item) force_fill_with_empty_string = false fields_with_values = {} 2.times.each do @fields.each do |field_name, block1| cell = block1.call(data_item) || '' fields_with_values[field_name] = cell unless !force_fill_with_empty_string && (cell.nil? || cell.strip.blank?) && @skip_empty_rows end if fields_with_values.empty? break else # If - finally - the row (that is, all cells) is *not* empty, all # template variables in all empty cells must be replaced by the # empty string. Otherwise the template variable is rendered # ("[some-template-var]")... force_fill_with_empty_string = true end end fields_with_values end |
#replace_values!(new_section, data_item) ⇒ Object
5 6 7 |
# File 'lib/odf-report/nested.rb', line 5 def replace_values!(new_section, data_item) node_hash_gsub!(new_section, get_fields_with_values(data_item)) end |