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



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

def initialize(options = {})
  super
  # 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



22
23
24
25
26
# File 'lib/prosereflect/mark/base.rb', line 22

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



29
30
31
32
33
# File 'lib/prosereflect/mark/base.rb', line 29

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