module Margin::Parser::LineMethods
Public Instance Methods
detect_annotation_only(string)
click to toggle source
# File lib/margin/parser.rb, line 48 def detect_annotation_only(string) string.match? ANNOTATION_ONLY end
detect_offset(string)
click to toggle source
Detect the offset of a raw line
# File lib/margin/parser.rb, line 33 def detect_offset(string) s = StringScanner.new(string) s.match? (/\s*/) end
detect_task(string)
click to toggle source
Detect if this matches the criteria for a task, Return the status and rest of string if yes, otherwise return false.
# File lib/margin/parser.rb, line 41 def detect_task(string) return false unless string.match? TASK_START done = string[1] != " " rest = string.sub(TASK_START,"") [done, rest] end
extract_annotation_value(string)
click to toggle source
Check if a value is really numeric, return the clean value
# File lib/margin/parser.rb, line 88 def extract_annotation_value(string) string = string.strip case when i = Integer(string, exception: false) then i when f = Float(string, exception: false) then f else string end end
extract_annotations(string)
click to toggle source
# File lib/margin/parser.rb, line 52 def extract_annotations(string) value = "" current_annotation = "" annotations = [] s = StringScanner.new(string) in_annotation = false until s.eos? c = s.getch case when c == "[" in_annotation = true when c == "]" in_annotation = false annotations << structure_annotation(current_annotation) current_annotation = "" when in_annotation current_annotation += c else value += c end end value = value.strip value = nil if value.length == 0 [value, annotations] end
strip_line(string)
click to toggle source
Get the inner value by scanning past all leading and trailing line decorations.
# File lib/margin/parser.rb, line 24 def strip_line(string) s = StringScanner.new(string) raw_inner = "" s.skip LINE_DECORATION raw_inner += s.getch until s.match? (/#{LINE_DECORATION}$/) raw_inner end
structure_annotation(string)
click to toggle source
# File lib/margin/parser.rb, line 78 def structure_annotation(string) first, last = string.split(":",2) if last { key: first.strip, value: extract_annotation_value(last) } else { value: extract_annotation_value(first) } end end