Class: Sidetree::Model::Service
- Inherits:
-
Object
- Object
- Sidetree::Model::Service
- Defined in:
- lib/sidetree/model/service.rb
Constant Summary collapse
- MAX_TYPE_LENGTH =
30
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
URI string or JSON object.
-
#id ⇒ Object
readonly
String.
-
#type ⇒ Object
readonly
String.
Class Method Summary collapse
-
.from_hash(data) ⇒ Sidetree::Model::Service
Generate service from json object.
Instance Method Summary collapse
-
#initialize(id, type, endpoint) ⇒ Service
constructor
A new instance of Service.
-
#to_h ⇒ Hash
Convert data to Hash object.
Constructor Details
#initialize(id, type, endpoint) ⇒ Service
Returns a new instance of Service.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sidetree/model/service.rb', line 11 def initialize(id, type, endpoint) Sidetree::Validator.validate_id!(id) raise Error, "type should be String." unless type.is_a?(String) if type.length > MAX_TYPE_LENGTH raise Error, "Service endpoint type length #{type.length} exceeds max allowed length of #{MAX_TYPE_LENGTH}." end if endpoint.is_a?(Array) raise Error, "Service endpoint value cannot be an array." end Sidetree::Validator.validate_uri!(endpoint) if endpoint.is_a?(String) @id = id @type = type @endpoint = endpoint end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
URI string or JSON object
8 9 10 |
# File 'lib/sidetree/model/service.rb', line 8 def endpoint @endpoint end |
#id ⇒ Object (readonly)
String
6 7 8 |
# File 'lib/sidetree/model/service.rb', line 6 def id @id end |
#type ⇒ Object (readonly)
String
7 8 9 |
# File 'lib/sidetree/model/service.rb', line 7 def type @type end |
Class Method Details
.from_hash(data) ⇒ Sidetree::Model::Service
Generate service from json object.
35 36 37 |
# File 'lib/sidetree/model/service.rb', line 35 def self.from_hash(data) Service.new(data["id"], data["type"], data["serviceEndpoint"]) end |
Instance Method Details
#to_h ⇒ Hash
Convert data to Hash object.
41 42 43 44 45 46 47 |
# File 'lib/sidetree/model/service.rb', line 41 def to_h hash = {} hash["id"] = id if id hash["type"] = type if type hash["serviceEndpoint"] = endpoint if endpoint hash end |