File: symbolized_markdown_helper.rb

package info (click to toggle)
ruby-ipynbdiff 0.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 148 kB
  • sloc: ruby: 363; makefile: 5
file content (30 lines) | stat: -rw-r--r-- 678 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module IpynbDiff
  # Helper functions
  module SymbolizedMarkdownHelper

    def _(symbol = nil, content = '')
      { symbol: symbol, content: content }
    end

    def array_if_not_array(thing)
      thing.is_a?(Array) ? thing : [thing]
    end

    def symbolize_array(symbol, content, &block)
      if content.is_a?(Array)
        content.map.with_index { |l, idx| _(symbol / idx, block.call(l)) }
      else
        _(symbol, content)
      end
    end
  end

  # Simple wrapper for a string
  class JsonSymbol < String
    def /(other)
      JsonSymbol.new((other.is_a?(Array) ? [self, *other] : [self, other]).join('.'))
    end
  end
end