Skip to content

Commit

Permalink
a couple of bugfixes and exception checking, added some specs to impl…
Browse files Browse the repository at this point in the history
…ement
  • Loading branch information
schacon committed Apr 17, 2008
1 parent acba45b commit 19a656d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/munger/data.rb
Expand Up @@ -16,7 +16,7 @@ def initialize(options = {})
end

def columns
@columns ||= @data.first.keys
@columns ||= clean_data(@data.first).to_hash.keys
end

# :default: The default value to use for the column in existing rows.
Expand Down
15 changes: 8 additions & 7 deletions lib/munger/report.rb
Expand Up @@ -200,19 +200,20 @@ def do_add_aggregate_rows
end

def calculate_aggregate(type, data)
return 0 if !data
if type.is_a? Proc
type.call(data)
else
case type
when :count
data.size
when :average
sum = data.inject {|sum, n| sum + n.to_i }
(sum / data.size)
sum = data.inject(0) {|sum, n| sum + n.to_i }
(sum / data.size).to_i rescue 0
when :product
data.inject {|prod, n| prod * n.to_i }
data.inject(0) {|prod, n| prod * n.to_i }
else
data.inject {|sum, n| sum + n.to_i }
data.inject(0) {|sum, n| sum + n.to_i }
end
end
end
Expand All @@ -236,14 +237,14 @@ def do_add_groupings
new_data << group_row
end
current[group] = next_row[:data][group]
level =- 1
level -= 1
end
else # last row
level = @grouping_level
sub.reverse.each do |group|
group_row = {:data => {}, :meta => {:group => 1}}
group_row = {:data => {}, :meta => {:group => level}}
new_data << group_row
level =- 1
level -= 1
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_data.rb
Expand Up @@ -113,4 +113,8 @@

it "should be able to group the data like sql" # like sql group command, give aggregation block

it "should be able to add two Munger::Datas together if they have the same columns"

it "(maybe) should be able to zip two Munger::Datas together given a unique key column in each"

end
2 changes: 2 additions & 0 deletions spec/spec_render_html.rb
Expand Up @@ -61,6 +61,8 @@
html = Munger::Render::Html.new(@report).render
html.should have_tag('td.highlight')
end

it "should render column styles"

it "should render default css if you ask"

Expand Down
4 changes: 4 additions & 0 deletions spec/spec_report.rb
Expand Up @@ -58,6 +58,8 @@
@report.get_subgroup_rows.should have(6).items
end

it "should be able to add subgroup headers"

it "should be able to subgroup in multiple dimensions"

it "should be able to aggregate columns into subgroup rows" do
Expand Down Expand Up @@ -125,6 +127,8 @@
janet[:cell_styles][:age].should eql(["highlight"])
end

it "should be able to style columns"

it "should be able to attach formatting independent of content"
# so can format numbers without hurting ability to aggregate correctly
# or add hyperlinks using data from columns not being shown
Expand Down

0 comments on commit 19a656d

Please sign in to comment.