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.



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

def initialize(label:, href:)
  @label = label.presence || 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



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

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



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

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

#to_jsonObject



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

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