class Margin::Item

Attributes

annotations[RW]
children[RW]
done[RW]
raw_data[RW]
type[RW]
value[RW]

Public Class Methods

from_line(line) click to toggle source
# 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
new(raw_data: "", type: :item, done: false, value: "", annotations: [], children: []) click to toggle source
# 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
root() click to toggle source
# File lib/margin/item.rb, line 51
def root
  new raw_data: "root", value: "root"
end

Public Instance Methods

as_json() click to toggle source
# 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?() click to toggle source
# File lib/margin/item.rb, line 27
def done?
  done
end
root?() click to toggle source
# File lib/margin/item.rb, line 31
def root?
  value == "root"
end
task?() click to toggle source
# File lib/margin/item.rb, line 23
def task?
  type == :task
end
to_json(pretty: false) click to toggle source
# File lib/margin/item.rb, line 46
def to_json(pretty: false)
  pretty ? JSON.pretty_generate(as_json) : JSON.generate(as_json)
end