Class: Arclight::DigitalObject

Inherits:
Object
  • Object
show all
Defined in:
lib/arclight/digital_object.rb

Overview

Plain ruby class to model serializing/deserializing digital object data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, href:) ⇒ DigitalObject

Returns a new instance of DigitalObject.



8
9
10
11
# File 'lib/arclight/digital_object.rb', line 8

def initialize(label:, href:)
  @label = label.present? ? label : href
  @href = href
end

Instance Attribute Details

#hrefObject (readonly)

Returns the value of attribute href.



7
8
9
# File 'lib/arclight/digital_object.rb', line 7

def href
  @href
end

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'lib/arclight/digital_object.rb', line 7

def label
  @label
end

Class Method Details

.from_json(json) ⇒ Object



17
18
19
20
# File 'lib/arclight/digital_object.rb', line 17

def self.from_json(json)
  object_data = JSON.parse(json)
  new(label: object_data['label'], href: object_data['href'])
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
# File 'lib/arclight/digital_object.rb', line 22

def ==(other)
  href == other.href && label == other.label
end

#to_jsonObject



13
14
15
# File 'lib/arclight/digital_object.rb', line 13

def to_json(*)
  { label: label, href: href }.to_json
end