Class: Margin::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/margin/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = "", format: :margin) ⇒ Document

Returns a new instance of Document.



10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/margin/document.rb', line 8

def root
  @root
end

Class Method Details

.from_json(input) ⇒ Object



41
42
43
# File 'lib/margin/document.rb', line 41

def from_json(input)
  new(input, format: :json)
end

.from_margin(input) ⇒ Object



37
38
39
# File 'lib/margin/document.rb', line 37

def from_margin(input)
  new(input, format: :margin)
end

Instance Method Details

#to_json(pretty: false) ⇒ Object



23
24
25
# File 'lib/margin/document.rb', line 23

def to_json(pretty: false)
  root.to_json(pretty: pretty)
end

#to_marginObject



19
20
21
# File 'lib/margin/document.rb', line 19

def to_margin
  ""
end