Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5 from alexander-sysuiev/master

'label' option was added to grouping options. to_html method was changed in test purpose.
  • Loading branch information...
commit 7454dfc1c4d0f5cf87f04e3557aa5943512a612e 2 parents d586363 + 384d7f2
@MitinPavel MitinPavel authored
View
7 lib/tabloid/data.rb
@@ -49,7 +49,12 @@ def groups_for(rows)
end
def label_for(key)
- key == :default ? false : key
+ return false if key == :default
+ if @grouping_options[:label]
+ @grouping_options[:label].call(key)
+ else
+ key
+ end
end
def csv_with_summary
View
10 lib/tabloid/report.rb
@@ -128,7 +128,7 @@ def data
end
def to_html
- "<table>#{data.to_html}</table>"
+ "<table id='#{generate_html_id}_table'>#{data.to_html}</table>"
end
def to_csv
@@ -256,5 +256,13 @@ def parameter_info_html
end
html.to_s
end
+
+ def generate_html_id
+ class_name = self.class.to_s
+ class_name.gsub!(/::/, '-')
+ class_name.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
+ class_name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
+ class_name.downcase!
+ end
end
end
View
13 spec/lib/tabloid/data_spec.rb
@@ -65,6 +65,19 @@
csv_rows.should include(["Totals (2 foos)", nil])
end
end
+ context "[label options is presented]" do
+ let(:data) do
+ Tabloid::Data.new(:report_columns => columns,
+ :rows => rows,
+ :grouping_key => :col1,
+ :grouping_options => { :label => lambda{|val| val.to_s + '_label_added'} })
+ end
+ it "changes default label" do
+ csv_rows = FasterCSV.parse(data.to_csv)
+ csv_rows.should include(["1_label_added", nil])
+ csv_rows.should include(["3_label_added", nil])
+ end
+ end
context "[cardinality options is presented]" do
let(:data) do
Tabloid::Data.new(:report_columns => columns,
Please sign in to comment.
Something went wrong with that request. Please try again.