module BookLab::SML::Utils

Public Instance Methods

attributes(node, add_if_mission: false) click to toggle source
# File lib/booklab/sml/utils.rb, line 17
def attributes(node, add_if_mission:  false)
  return {} if node.blank?
  return node[1].deep_symbolize_keys if has_attributes?(node)
  return {} unless add_if_mission

  name = node.shift || ""
  attrs = {}
  node.unshift(attrs)
  node.unshift(name)

  attrs
end
attributes?(node) click to toggle source
# File lib/booklab/sml/utils.rb, line 35
def attributes?(node)
  return false if node.nil?
  node.is_a?(Hash)
end
element?(node) click to toggle source
# File lib/booklab/sml/utils.rb, line 40
def element?(node)
  node.is_a?(Array) && node[0].is_a?(String)
end
get_children(node) click to toggle source
# File lib/booklab/sml/utils.rb, line 8
def get_children(node)
  has_attributes?(node) ? node[2..-1] : node[1..-1]
end
has_attributes?(node) click to toggle source
# File lib/booklab/sml/utils.rb, line 30
def has_attributes?(node)
  return false unless element?(node)
  attributes?(node[1])
end
tag_name(node) click to toggle source
# File lib/booklab/sml/utils.rb, line 12
def tag_name(node)
  return nil if node.blank?
  node[0] || ""
end