Class: WorkingClass::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/working_class/parser.rb

Overview

The actual syntax parser

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ WorkingClass::Parser

Initializes a new Parser object with a given WorkingClass syntax string

Parameters:

  • string (String)

    the raw string with the WorkingClass syntax



13
14
15
16
17
# File 'lib/working_class/parser.rb', line 13

def initialize(string)
  @raw_string = string
  @date_regex = /(?:\d{1,2}\.){2}\d{2,4}/
  @time_regex = /\d{1,2}:\d{1,2}/
end

Instance Method Details

#to_hHash

Parses the syntax and returns an Hash with the result

Returns:

  • (Hash)

    a Hash representation of the parsed tasklist



23
24
25
26
27
28
29
# File 'lib/working_class/parser.rb', line 23

def to_h
  {
    name: tasklist_name,
    tasks_count: tasks.length,
    tasks: tasks
  }
end

#to_tasklistWorkingClass::Tasklist

Parses the syntax and returns a WorkingClass::Tasklist instance

Returns:



35
36
37
38
39
40
41
42
43
# File 'lib/working_class/parser.rb', line 35

def to_tasklist
  tasks = Array.new
  raw = self.to_h
  raw[:tasks].each do |t|
    task = Task.new(t[:name], t)
    tasks << task
  end
  Tasklist.new raw[:name], tasks
end