Class: NodeInfo::Document

Inherits:
Struct
  • Object
show all
Defined in:
lib/node_info.rb

Overview

rubocop:disable Metrics/BlockLength

Defined Under Namespace

Classes: Protocols, Services, Software, Usage

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version = nil, open_registrations = nil, metadata = {}) ⇒ Document

Returns a new instance of Document.


91
92
93
# File 'lib/node_info.rb', line 91

def initialize(version=nil, open_registrations=nil, ={})
  super(version, Software.new, Protocols.new, Services.new, open_registrations, Usage.new, )
end

Instance Attribute Details

#metadataObject

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata


12
13
14
# File 'lib/node_info.rb', line 12

def 
  @metadata
end

#open_registrationsObject

Returns the value of attribute open_registrations

Returns:

  • (Object)

    the current value of open_registrations


12
13
14
# File 'lib/node_info.rb', line 12

def open_registrations
  @open_registrations
end

#protocolsObject

Returns the value of attribute protocols

Returns:

  • (Object)

    the current value of protocols


12
13
14
# File 'lib/node_info.rb', line 12

def protocols
  @protocols
end

#servicesObject

Returns the value of attribute services

Returns:

  • (Object)

    the current value of services


12
13
14
# File 'lib/node_info.rb', line 12

def services
  @services
end

#softwareObject

Returns the value of attribute software

Returns:

  • (Object)

    the current value of software


12
13
14
# File 'lib/node_info.rb', line 12

def software
  @software
end

#usageObject

Returns the value of attribute usage

Returns:

  • (Object)

    the current value of usage


12
13
14
# File 'lib/node_info.rb', line 12

def usage
  @usage
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version


12
13
14
# File 'lib/node_info.rb', line 12

def version
  @version
end

Class Method Details

.buildObject


84
85
86
87
88
89
# File 'lib/node_info.rb', line 84

def self.build
  new.tap do |doc|
    yield doc
    doc.validate
  end
end

Instance Method Details

#as_json(_options = {}) ⇒ Object


95
96
97
98
99
100
101
102
# File 'lib/node_info.rb', line 95

def as_json(_options={})
  case version
  when "1.0"
    version_10_hash
  when "2.0"
    version_20_hash
  end
end

#content_typeObject


104
105
106
# File 'lib/node_info.rb', line 104

def content_type
  "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/#{version}#"
end

#schemaObject


108
109
110
# File 'lib/node_info.rb', line 108

def schema
  NodeInfo.schema version
end

#validateObject


112
113
114
115
# File 'lib/node_info.rb', line 112

def validate
  assert NodeInfo.supported_version?(version), "Unknown version #{version}"
  JSON::Validator.validate!(schema, as_json)
end