Class: Paragraph::Markup

Inherits:
Object
  • Object
show all
Defined in:
lib/Models/Paragraph.rb

Constant Summary collapse

SEMANTIC_KEYS =

Semantic identity fields used for ‘==` / `eql?` / `hash`. `start` and `end` are interval coordinates (handled by Rangeable as the [lo, hi] pair) rather than identity. `linkMetadata` is currently unused downstream so it is excluded too. This identity is what lets Rangeable merge two Markups that describe the same logical span (e.g. two STRONG runs that overlap) into a single coalesced interval.

[:type, :href, :anchorType, :userId].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Markup

Returns a new instance of Markup.



31
32
33
34
35
36
37
38
39
# File 'lib/Models/Paragraph.rb', line 31

def initialize(json)
    @type = json['type']
    @start = json['start']
    @end = json['end']
    @href = json['href']
    @anchorType = json['anchorType']
    @userId = json['userId']
    @linkMetadata = json['linkMetadata']
end

Instance Attribute Details

#anchorTypeObject

Returns the value of attribute anchorType.



20
21
22
# File 'lib/Models/Paragraph.rb', line 20

def anchorType
  @anchorType
end

#endObject

Returns the value of attribute end.



20
21
22
# File 'lib/Models/Paragraph.rb', line 20

def end
  @end
end

#hrefObject

Returns the value of attribute href.



20
21
22
# File 'lib/Models/Paragraph.rb', line 20

def href
  @href
end

#linkMetadataObject

Returns the value of attribute linkMetadata.



20
21
22
# File 'lib/Models/Paragraph.rb', line 20

def 
  @linkMetadata
end

#startObject

Returns the value of attribute start.



20
21
22
# File 'lib/Models/Paragraph.rb', line 20

def start
  @start
end

#typeObject

Returns the value of attribute type.



20
21
22
# File 'lib/Models/Paragraph.rb', line 20

def type
  @type
end

#userIdObject

Returns the value of attribute userId.



20
21
22
# File 'lib/Models/Paragraph.rb', line 20

def userId
  @userId
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



41
42
43
44
# File 'lib/Models/Paragraph.rb', line 41

def ==(other)
    return false unless other.is_a?(Markup)
    SEMANTIC_KEYS.all? { |k| public_send(k) == other.public_send(k) }
end

#hashObject



47
48
49
# File 'lib/Models/Paragraph.rb', line 47

def hash
    SEMANTIC_KEYS.map { |k| public_send(k) }.hash
end