Sha256: 993c922e55ecd5002c9b83c7a4450fc68758110a28719b3d35b473865cefb10f
Contents?: true
Size: 379 Bytes
Versions: 3
Compression:
Stored size: 379 Bytes
Contents
require 'active_record' module ActiveRecord class Relation def percentage(*filters) return 0 if count == 0 if filters.first.is_a?(Symbol) filtered = filters.inject(self) do |relation, scope| relation.public_send(scope) end else filtered = where(*filters) end filtered.count * 1.0 / count end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bidu-house-0.1.2 | lib/active_record/relation_ext.rb |
bidu-house-0.1.1 | lib/active_record/relation_ext.rb |
bidu-house-0.1.0 | lib/active_record/relation_ext.rb |