Sha256: 35cbcf8a9a305322cf68e84978ffea266b77d43e9ae910a2900da92e320196a6
Contents?: true
Size: 945 Bytes
Versions: 2
Compression:
Stored size: 945 Bytes
Contents
require_relative 'serialization/to_wire' require_relative 'serialization/lines' require_relative 'serialization/csv' require_relative 'serialization/tsv' require_relative 'serialization/json' class Array def to_tsv to_wire.join("\t") end end module Gorillib module Model def to_wire(options={}) compact_attributes.merge(:_type => self.class.typename).inject({}) do |acc, (key,attr)| acc[key] = attr.respond_to?(:to_wire) ? attr.to_wire(options) : attr acc end end def as_json(*args) to_wire(*args) ; end def to_json(options={}) MultiJson.dump(to_wire(options), options) end def to_tsv(options={}) attributes.map do |key, attr| attr.respond_to?(:to_wire) ? attr.to_wire(options) : attr end.join("\t") end module ClassMethods def from_tuple(*vals) receive Hash[field_names[0..vals.length-1].zip(vals)] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gorillib-model-0.0.3 | lib/gorillib/model/serialization.rb |
gorillib-model-0.0.1 | lib/gorillib/model/serialization.rb |