lib/jcompiler.rb in jcompiler-0.1.17 vs lib/jcompiler.rb in jcompiler-0.1.18
- old
+ new
@@ -1,7 +1,10 @@
class Jcompiler
def self.b(brand)
- ["\"id\":#{brand.id}", "\"name\":#{ActiveSupport::JSON.encode(brand.name)}"]
+ %i(id, name, description).map do |sym|
+ v = brand.send(sym)
+ "\"#{sym}\":#{v.is_a?(String) ? ActiveSupport::JSON.encode(v) : v ? v.to_s : 'null'}"
+ end
end
def self.a(brands)
brands.map do |brand|
"{#{b(brand).join(',')}}"