Module: EDN

Defined in:
lib/edn.rb,
lib/edn/parser.rb,
lib/edn/version.rb,
lib/edn/core_ext.rb,
lib/edn/transform.rb,
lib/edn/type/list.rb,
lib/edn/type/uuid.rb,
lib/edn/type/symbol.rb,
lib/edn/type/unknown.rb,
lib/edn/string_transformer.rb

Defined Under Namespace

Modules: CoreExt, StringTransformer, Type Classes: Parser, Transform

Constant Summary collapse

VERSION =
"0.9.1"

Class Method Summary collapse

Class Method Details

.read(edn) ⇒ Object



12
13
14
# File 'lib/edn.rb', line 12

def self.read(edn)
  @transform.apply(@parser.parse(edn))
end

.register(tag, func = nil, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/edn.rb', line 16

def self.register(tag, func = nil, &block)
  if block_given?
    func = block
  end

  raise "EDN.register requires a block or callable." if func.nil?

  if func.is_a?(Class)
    @tags[tag] = lambda { |*args| func.new(*args) }
  else
    @tags[tag] = func
  end
end

.tag_value(tag, value) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/edn.rb', line 34

def self.tag_value(tag, value)
  func = @tags[tag]
  if func
    func.call(value)
  else
    EDN::Type::Unknown.new(tag, value)
  end
end

.tagout(tag, value) ⇒ Object



43
44
45
# File 'lib/edn.rb', line 43

def self.tagout(tag, value)
  ["##{tag}", value.to_edn].join(" ")
end

.unregister(tag) ⇒ Object



30
31
32
# File 'lib/edn.rb', line 30

def self.unregister(tag)
  @tags[tag] = nil
end