class Pwl::EntryMapper
DataMapper that maps an Entry
from and to JSON
Constants
- ATTRIBUTES
Public Class Methods
from_json(str)
click to toggle source
# File lib/pwl/entry_mapper.rb, line 10 def from_json(str) json = JSON(str, :symbolize_names => true) Entry.new.tap do |entry| ATTRIBUTES.each do |attr| entry.send("#{attr}=", json[attr.to_sym]) end end end
to_json(entry)
click to toggle source
# File lib/pwl/entry_mapper.rb, line 20 def to_json(entry) entry.validate! result = {} ATTRIBUTES.each do |attr| result.store(attr.to_sym, entry.send(attr)) end result.to_json end