class Margin::Document
Attributes
root[R]
Public Class Methods
new(input="", format: :margin)
click to toggle source
# File lib/margin/document.rb, line 10 def initialize(input="", format: :margin) @root = Item.root case format when :margin then parse_margin!(input) when :json then parse_json!(input) else raise ArgumentError, "Allowed formats: :margin, :json" end end
Private Class Methods
from_json(input)
click to toggle source
# File lib/margin/document.rb, line 41 def from_json(input) new(input, format: :json) end
from_margin(input)
click to toggle source
# File lib/margin/document.rb, line 37 def from_margin(input) new(input, format: :margin) end
Public Instance Methods
to_json(pretty: false)
click to toggle source
# File lib/margin/document.rb, line 23 def to_json(pretty: false) root.to_json(pretty: pretty) end
to_margin()
click to toggle source
# File lib/margin/document.rb, line 19 def to_margin "" end
Private Instance Methods
parse_json!(input)
click to toggle source
# File lib/margin/document.rb, line 33 def parse_json!(input) end
parse_margin!(input)
click to toggle source
# File lib/margin/document.rb, line 29 def parse_margin!(input) @root = Parser.parse(input) end