Class: Tablifier::Base
- Inherits:
-
Object
- Object
- Tablifier::Base
- Extended by:
- ERB::Util
- Includes:
- Singleton
- Defined in:
- lib/tablifier/tablifier.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.tablify(obj) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tablifier/tablifier.rb', line 10 def self.tablify obj raise ArgumentError, "tablify is only implemented for Hash and ActiveRecord objects, not: '#{obj.class_name}'" unless obj.is_a?(Hash) || obj.is_a?(ActiveRecord::Base) @class_name = obj.class.name @h = if obj.is_a?(ActiveRecord::Base) @obj_id = obj.id @to_s = obj.to_s obj.attributes else @obj_id = nil @to_s = nil obj.map{|k,v| [k.to_s,v]}.to_h end instance.erb.result(binding).html_safe end |
Instance Method Details
#erb ⇒ Object
6 7 8 |
# File 'lib/tablifier/tablifier.rb', line 6 def erb @erb ||= ERB.new File.open(File.join(Gem::Specification.find_by_name('tablifier').gem_dir, 'lib', 'tablifier', 'template.html.erb')).read end |