Class: Margin::Item
- Inherits:
-
Object
- Object
- Margin::Item
- Defined in:
- lib/margin/item.rb
Instance Attribute Summary collapse
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#children ⇒ Object
Returns the value of attribute children.
-
#done ⇒ Object
Returns the value of attribute done.
-
#raw_data ⇒ Object
Returns the value of attribute raw_data.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #done? ⇒ Boolean
-
#initialize(raw_data: "", type: :item, done: false, value: "", annotations: [], children: []) ⇒ Item
constructor
A new instance of Item.
- #root? ⇒ Boolean
- #task? ⇒ Boolean
- #to_json(pretty: false) ⇒ Object
Constructor Details
#initialize(raw_data: "", type: :item, done: false, value: "", annotations: [], children: []) ⇒ Item
Returns a new instance of Item.
14 15 16 17 18 19 20 21 |
# File 'lib/margin/item.rb', line 14 def initialize(raw_data: "", type: :item, done: false, value: "", annotations: [], children: []) @raw_data = raw_data @type = type @done = done @value = value @annotations = annotations @children = children end |
Instance Attribute Details
#annotations ⇒ Object
Returns the value of attribute annotations.
7 8 9 |
# File 'lib/margin/item.rb', line 7 def annotations @annotations end |
#children ⇒ Object
Returns the value of attribute children.
7 8 9 |
# File 'lib/margin/item.rb', line 7 def children @children end |
#done ⇒ Object
Returns the value of attribute done.
7 8 9 |
# File 'lib/margin/item.rb', line 7 def done @done end |
#raw_data ⇒ Object
Returns the value of attribute raw_data.
7 8 9 |
# File 'lib/margin/item.rb', line 7 def raw_data @raw_data end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/margin/item.rb', line 7 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/margin/item.rb', line 7 def value @value end |
Class Method Details
.from_line(line) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/margin/item.rb', line 55 def from_line(line) new raw_data: line.raw_data, type: line.type, value: line.value, done: line.done, annotations: line.annotations end |
.root ⇒ Object
51 52 53 |
# File 'lib/margin/item.rb', line 51 def root new raw_data: "root", value: "root" end |
Instance Method Details
#as_json ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/margin/item.rb', line 35 def as_json h = {} h[:raw_data] = raw_data h[:type] = type h[:value] = value h[:done] = done if type == :task h[:annotations] = annotations h[:children] = children.map(&:as_json) h end |
#done? ⇒ Boolean
27 28 29 |
# File 'lib/margin/item.rb', line 27 def done? done end |
#root? ⇒ Boolean
31 32 33 |
# File 'lib/margin/item.rb', line 31 def root? value == "root" end |
#task? ⇒ Boolean
23 24 25 |
# File 'lib/margin/item.rb', line 23 def task? type == :task end |
#to_json(pretty: false) ⇒ Object
46 47 48 |
# File 'lib/margin/item.rb', line 46 def to_json(pretty: false) pretty ? JSON.pretty_generate(as_json) : JSON.generate(as_json) end |