Class: Prosereflect::Mark::Base

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/prosereflect/mark/base.rb

Direct Known Subclasses

Bold, Code, Italic, Link, Strike, Subscript, Superscript, Underline

Constant Summary collapse

PM_TYPE =
'mark'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Override initialize to ensure the type is set correctly



38
39
40
41
42
43
44
45
46
# File 'lib/prosereflect/mark/base.rb', line 38

def initialize(options = {})
  super(options)
  # Only set the type to PM_TYPE if no type was provided in options
  self.type = begin
    options[:type] || self.class.const_get(:PM_TYPE)
  rescue StandardError
    'mark'
  end
end

Class Method Details

.create(attrs = nil) ⇒ Object



24
25
26
27
28
# File 'lib/prosereflect/mark/base.rb', line 24

def self.create(attrs = nil)
  new(type: const_get(:PM_TYPE), attrs: attrs)
rescue NameError
  new(type: 'mark', attrs: attrs)
end

Instance Method Details

#to_hObject

Convert to hash for serialization



31
32
33
34
35
# File 'lib/prosereflect/mark/base.rb', line 31

def to_h
  result = { 'type' => type }
  result['attrs'] = attrs if attrs && !attrs.empty?
  result
end