Class: Prosereflect::Schema::NodeSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/prosereflect/schema/spec.rb

Overview

Represents a node specification from a schema

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, attrs: {}, content: nil, groups: [], inline: false, atom: false, marks: nil) ⇒ NodeSpec

Returns a new instance of NodeSpec.



9
10
11
12
13
14
15
16
17
18
# File 'lib/prosereflect/schema/spec.rb', line 9

def initialize(name:, attrs: {}, content: nil, groups: [], inline: false,
atom: false, marks: nil)
  @name = name
  @attrs = attrs
  @content = content
  @groups = groups
  @inline = inline
  @atom = atom
  @marks = marks
end

Instance Attribute Details

#atomObject (readonly)

Returns the value of attribute atom.



7
8
9
# File 'lib/prosereflect/schema/spec.rb', line 7

def atom
  @atom
end

#attrsObject (readonly)

Returns the value of attribute attrs.



7
8
9
# File 'lib/prosereflect/schema/spec.rb', line 7

def attrs
  @attrs
end

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/prosereflect/schema/spec.rb', line 7

def content
  @content
end

#groupsObject (readonly)

Returns the value of attribute groups.



7
8
9
# File 'lib/prosereflect/schema/spec.rb', line 7

def groups
  @groups
end

#inlineObject (readonly)

Returns the value of attribute inline.



7
8
9
# File 'lib/prosereflect/schema/spec.rb', line 7

def inline
  @inline
end

#marksObject (readonly)

Returns the value of attribute marks.



7
8
9
# File 'lib/prosereflect/schema/spec.rb', line 7

def marks
  @marks
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/prosereflect/schema/spec.rb', line 7

def name
  @name
end

Class Method Details

.from_hash(name, spec) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/prosereflect/schema/spec.rb', line 20

def self.from_hash(name, spec)
  new(
    name: name,
    attrs: spec[:attrs] || spec["attrs"] || {},
    content: spec[:content] || spec["content"],
    groups: parse_groups(spec),
    inline: spec[:inline] || spec["inline"] || false,
    atom: spec[:atom] || spec["atom"] || false,
    marks: spec[:marks] || spec["marks"],
  )
end

.parse_groups(spec) ⇒ Object



32
33
34
35
36
37
# File 'lib/prosereflect/schema/spec.rb', line 32

def self.parse_groups(spec)
  group_str = spec[:group] || spec["group"]
  return [] unless group_str

  group_str.is_a?(Array) ? group_str : group_str.to_s.split
end