Class: Margin::Document
- Inherits:
-
Object
- Object
- Margin::Document
- Defined in:
- lib/margin/document.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input = "", format: :margin) ⇒ Document
constructor
A new instance of Document.
- #to_json(pretty: false) ⇒ Object
- #to_margin ⇒ Object
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
#root ⇒ Object (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_margin ⇒ Object
19 20 21 |
# File 'lib/margin/document.rb', line 19 def to_margin "" end |