Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/json/add/core.rb

Overview

Date serialization/deserialization

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.json_create(object) ⇒ Object

Deserializes JSON string by converting Julian year y, month m, day d and Day of Calendar Reform sg to Date.



68
69
70
# File 'lib/json/add/core.rb', line 68

def self.json_create(object)
  civil(*object.values_at('y', 'm', 'd', 'sg'))
end

Instance Method Details

#as_jsonObject

Returns a hash, that will be turned into a JSON object and represent this object.



76
77
78
79
80
81
82
83
84
# File 'lib/json/add/core.rb', line 76

def as_json(*)
  {
    JSON.create_id => self.class.name,
    'y' => year,
    'm' => month,
    'd' => day,
    'sg' => start,
  }
end

#to_json(*args) ⇒ Object

Stores class name (Date) with Julian year y, month m, day d and Day of Calendar Reform sg as JSON string



88
89
90
# File 'lib/json/add/core.rb', line 88

def to_json(*args)
  as_json.to_json(*args)
end