Class: PigeonHole::JSONDate

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/pigeon_hole/json_date.rb,
lib/pigeon_hole/monster-vim-2016-07-25-16-44-47.rb,
lib/pigeon_hole/monster-vim-2016-07-25-16-47-36.rb,
lib/pigeon_hole/monster-vim-2016-07-25-16-47-37.rb,
lib/pigeon_hole/monster-vim-2016-07-25-16-47-38.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.



5
6
7
# File 'lib/pigeon_hole/json_date.rb', line 5

def self.json_create(object)
  Date.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.



13
14
15
16
17
18
19
20
21
# File 'lib/pigeon_hole/json_date.rb', line 13

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



25
26
27
# File 'lib/pigeon_hole/json_date.rb', line 25

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