flexy-odf-report 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,42 +11,20 @@ class Table
11
11
  @collection = opts[:collection]
12
12
  @header = opts[:header] || false
13
13
 
14
+ @skip_empty_rows = opts[:skip_empty_rows] || false
15
+
14
16
  @fields = {}
15
17
  @rows = []
16
18
  @data = []
17
19
  end
18
20
 
19
- #
20
- # Old version
21
- #
22
21
  def add_column(name, field=nil, &block)
23
- add_column_if(true, name, field, &block)
24
- end
25
-
26
- #
27
- # New version
28
- #
29
- # Adds column only if condition is not evaluated to false.
30
-
31
- # If condition equals :skip_blank_fields and both, field
32
- # is nil and no block is given then nothing is done (no
33
- # column is added).
34
- #
35
- def add_column_if(condition, name, field=nil, &block)
36
- if condition
37
- block_result = yield if block_given?
38
-
39
- # Only render the column if condition holds true...
40
- if condition == :skip_blank_fields &&
41
- (field.nil? || field.strip.blank?) && (block.nil? || block_result.nil?)
42
- # Do nothing!
43
- elsif field
44
- @fields[name] = lambda { |item| item.send(field)}
45
- elsif block_given?
46
- @fields[name] = block
47
- else
48
- @fields[name] = lambda { |item| item.send(name)}
49
- end
22
+ if field
23
+ @fields[name] = lambda { |item| item.send(field) }
24
+ elsif block_given?
25
+ @fields[name] = block
26
+ else
27
+ @fields[name] = lambda { |item| item.send(name) }
50
28
  end
51
29
  end
52
30
 
@@ -55,9 +33,10 @@ class Table
55
33
  collection.each do |item|
56
34
  row = {}
57
35
  @fields.each do |field_name, block1|
58
- row[field_name] = block1.call(item) || ''
36
+ cell = block1.call(item) || ''
37
+ row[field_name] = cell unless (cell.nil? || cell.strip.blank?) && @skip_empty_rows
59
38
  end
60
- ret << row
39
+ ret << row unless row.empty? && @skip_empty_rows
61
40
  end
62
41
  ret
63
42
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{flexy-odf-report}
5
- s.version = "0.1.4"
5
+ s.version = "0.1.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sandro Duarte", "Mark von Zeschau"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: flexy-odf-report
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sandro Duarte