syc-task 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTA1MGU1ZWJhNTQwMTQ2MzczY2M0ZjcyODUwMjdjYWFhY2Y4NzE5OA==
4
+ ZmE1ZjUxZWYwNzIxNGNlOWMxMDU2N2M1YzFiMzBlODY2NWEyZWI3NA==
5
5
  data.tar.gz: !binary |-
6
- NjliNTYxODBjMTYxYTc4NjM1YTY0YjA5YmZlMDEyZDkyNDlmMjFjNg==
6
+ MmRkMzk0ZWZiYmZjY2M1MjE0ZjQ3MzA2NTZmNzNjMDMzMTgxMjExZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGE4YzkwMWYyMjZkOWI0ZDMwYzVlZWIyY2I1NWY4YTgyODIzZmNhMjAzNThi
10
- NjIzZjZlOTQ0N2IwOTU4ZjI4MTJlNjQ2YzYxOWI5NTBiMTMxMjVhMjVkNDQ5
11
- N2JiYWU5MDRjNjQ0NWU0NTlmYzUwODliMWU2YWQxMjRiNTIwODI=
9
+ MmM5MTdlOTNmZjU2ZmYwZDhlOTM0ODNjOTA0NGE0ZmUyMGU0YTUwZDhhNDc3
10
+ NDI5Mzk5OWNiMTg2NWUwOWY0ZWM0YjIzNDA1MzE1NWU0MzNkMTVlNTU1YTg2
11
+ MjY1YmE5NmQ3OWIyOGYyOGM4YmNhMzg5YzJhOTI0MjNiNmYwZmU=
12
12
  data.tar.gz: !binary |-
13
- YjdkMTFlMzExMjA3YjIwM2RlZTdjN2JjZTc5YWMwNTQ0YTIxZmE4ZmE0N2I1
14
- NmZhMGQyMGIyZjcwMDEwMmIxMTBiZTNhZWU3MjEwODUxMzBlYWQ4ZmQwY2My
15
- ODA4N2Q1NmNmMjQxZjlmZWZkOGQ1ZTU4MTc4Njg3OWQ2ODUxNWE=
13
+ MGY5ZGE4NjZkYTJhMGYzNzBjNmMyZjkyMWYzMGMyOWMyNTliMGQ3ZDIyNjg4
14
+ OTYwMDdiMWMxZWI2Mjc4YjRjMDAzYzA3NzdhYjczMzIwNjA0MTg0NzY5NWU5
15
+ ZTMyYmM2Y2I2ZTE2ZjRjMmUzNGE2MTMwNzU0M2VhM2FiMTcyY2M=
@@ -0,0 +1,130 @@
1
+ require_relative 'task'
2
+
3
+ # Syctask provides functions for managing tasks in a task list
4
+ module Syctask
5
+
6
+ # A Scanner scans text or files for tasks. The task is identified by an
7
+ # annotation
8
+ #
9
+ # Example
10
+ # -------
11
+ # @tasks;
12
+ # title;description;prio;follow_up
13
+ # Title 1;Description 1;;2016-09-10
14
+ # Title 2;Description 2;1;2016-09-20
15
+ #
16
+ # @tasks; is indicating that tasks are following separated by ';'. The next
17
+ # line describes to which fields the values belong to. The next lines are the
18
+ # actual field values.
19
+ class Scanner
20
+
21
+ # The scan type @tasks scan all tasks, @task scan the next task
22
+ attr_reader :scan
23
+ # Indicates whether task has been scanned since last @task(s) annotation
24
+ attr_reader :scanned
25
+ # The separator that separates task values
26
+ attr_reader :separator
27
+ # The task fields
28
+ attr_reader :task_fields
29
+ # The task counter holding tasks scanned
30
+ attr_reader :task_count
31
+ # The scanned tasks
32
+ attr_reader :tasks
33
+
34
+ # Creates a new scanner
35
+ def initialize
36
+ @tasks = {}
37
+ end
38
+
39
+ # Scans the content in regard to tasks. 'content' may be a file or a string.
40
+ # It checks if 'content' is a file and if it exists scans the file otherwise
41
+ # it asumes the content to be text and scans accordingly.
42
+ def scan(content)
43
+ if File.exists? content
44
+ scan_file(content)
45
+ else
46
+ scan_text(content)
47
+ end
48
+ @tasks
49
+ end
50
+
51
+ # Scans a file for tasks
52
+ def scan_file(file)
53
+ File.foreach(file) do |line|
54
+ scan_line(line.strip)
55
+ end
56
+ end
57
+
58
+ # Scans a text for tasks
59
+ def scan_text(text)
60
+ text.each_line do |line|
61
+ scan_line(line.strip)
62
+ end
63
+ end
64
+
65
+ # Scans a string (line) for tasks
66
+ def scan_line(line)
67
+ if line =~ /^@tasks./i
68
+ @scan, @separator = line.scan(/(@tasks)(.)/i).flatten
69
+ @scanned = false
70
+ elsif line =~ /^@task./i
71
+ @scan, @separator = line.scan(/(@task)(.)/i).flatten
72
+ @scanned = false
73
+ else
74
+ if not @scanned
75
+ load_task_fields(line) || scan_task_line(line)
76
+ elsif multiple_scan?
77
+ scan_task_line(line)
78
+ end
79
+ end
80
+ end
81
+
82
+ # Checks if the 'line' contains task fields. If it contains task fields it
83
+ # sets the @task_fields and returns true, otherwise returns false
84
+ def load_task_fields(line)
85
+ task_fields = line.split(@separator)
86
+ if (Syctask::Task::FIELDS & task_fields).empty?
87
+ false
88
+ else
89
+ @task_fields = task_fields.map { |f| f.strip.downcase.to_sym }
90
+ true
91
+ end
92
+ end
93
+
94
+ # Scans the 'line' for task values
95
+ def scan_task_line(line)
96
+ return if line.start_with? '-'
97
+ task_values = line.split(@separator)
98
+ if @task_fields && (@task_fields.size == task_values.size)
99
+ @tasks[title_of(task_values)] = options_of(task_values)
100
+ @scanned = true
101
+ end
102
+ end
103
+
104
+ # Retrieves the 'title' value from the task_values which is an array
105
+ def title_of(task_values)
106
+ task_values[@task_fields.index(:title)].strip
107
+ end
108
+
109
+
110
+ # Retrieves the task values except for the 'title' value and returns a
111
+ # hash of the task values
112
+ def options_of(task_values)
113
+ task_values = task_values - [task_values[@task_fields.index(:title)]]
114
+ task_fields = @task_fields - [:title]
115
+ options = {}
116
+ task_fields.each_with_index do |field, index|
117
+ options[field] = task_values[index].strip
118
+ end
119
+ options
120
+ end
121
+
122
+ # Checks whether multiple tasks should be scanned which is indicated by
123
+ # '@scan == '@tasks'.
124
+ def multiple_scan?
125
+ @scan =~ /@tasks/i
126
+ end
127
+ end
128
+
129
+ end
130
+
@@ -1,5 +1,5 @@
1
1
  # Syctask provides functions for managing tasks in a task list
2
2
  module Syctask
3
3
  #Holds the version number of syctask
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syc-task
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Sugar
@@ -389,6 +389,7 @@ files:
389
389
  - lib/syctask/environment.rb
390
390
  - lib/syctask/evaluator.rb
391
391
  - lib/syctask/meeting.rb
392
+ - lib/syctask/scanner.rb
392
393
  - lib/syctask/schedule.rb
393
394
  - lib/syctask/settings.rb
394
395
  - lib/syctask/statistics.rb