Class: Date

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

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.



11
12
13
# File 'lib/json/add/date.rb', line 11

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.



19
20
21
22
23
24
25
26
27
# File 'lib/json/add/date.rb', line 19

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



31
32
33
# File 'lib/json/add/date.rb', line 31

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