Module: Steem::JSONable

Included in:
Operation, Transaction
Defined in:
lib/steem/mixins/jsonable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
# File 'lib/steem/mixins/jsonable.rb', line 13

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#as_json(options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/steem/mixins/jsonable.rb', line 17

def as_json options = {}
  serialized = Hash.new
  
  self.class.attributes.each do |attribute|
    unless (value = self.public_send attribute).nil?
      serialized[attribute] = if value.respond_to? :strftime
        value.strftime('%Y-%m-%dT%H:%M:%S')
      else
        value
      end
    end
  end
  
  serialized
end

#to_json(*a) ⇒ Object



33
34
35
# File 'lib/steem/mixins/jsonable.rb', line 33

def to_json *a
  as_json.to_json *a
end