Method: Useless::Doc::Serialization::Load.domain

Defined in:
lib/useless/doc/serialization/load.rb

.domain(json) ⇒ Core::Domain

Converts a JSON represntation to an instance of Core::Domain

Parameters:

  • json (String, Hash)

    the JSON representation to be converted to a domain.

Returns:

  • (Core::Domain)

    the domain corresponding to the specified JSON.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/useless/doc/serialization/load.rb', line 48

def self.domain(json)
  hash = json_to_hash json

  apis = (hash['apis'] || []).map do |json|
    api json
  end

  timestamp = begin
    Time.parse(hash['timestamp'])
  rescue TypeError, ArgumentError
    nil
  end

  Useless::Doc::Core::Domain.new \
    name:         hash['name'], 
    url:          hash['url'],
    timestamp:    timestamp,
    description:  hash['description'],
    apis:         apis
end