ztrening 0.0.4.1 → 0.0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/zt +13 -5
- data/lib/ztrening.rb +92 -2
- metadata +4 -4
data/bin/zt
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
7
|
require File.expand_path(File.dirname(__FILE__) + "/../lib/ztrening")
|
8
|
+
require "fileutils"
|
8
9
|
|
9
10
|
include ZtreningM
|
10
11
|
|
@@ -95,11 +96,15 @@ elsif ARGV[0] == 'find'
|
|
95
96
|
elsif ARGV[0] == 'list'
|
96
97
|
z = Ztrening.new
|
97
98
|
z.lista_txt
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
99
|
+
elsif %w[todo t].include? ARGV[0]
|
100
|
+
if %w[show list ls l].include? ARGV[1]
|
101
|
+
puts TodoFile.list
|
102
|
+
elsif %w[add new].include? ARGV[1] and ARGV[2] and !ARGV[3]
|
103
|
+
ConfDir.create_if_ne
|
104
|
+
TodoFile.add ARGV[2]
|
105
|
+
elsif %w[del rm delete remove].include? ARGV[1] and ARGV[2] and !ARGV[3]
|
106
|
+
TodoFile.delete ARGV[2]
|
107
|
+
end
|
103
108
|
# TODO: zt set ZADATAK STATUS
|
104
109
|
# elsif ARGV[0] == 'set'
|
105
110
|
# if ARGV[1]
|
@@ -111,6 +116,9 @@ elsif ARGV[0] == 'list'
|
|
111
116
|
# exit
|
112
117
|
# end
|
113
118
|
elsif ARGV[0] == 'init'
|
119
|
+
puts "Not implemented"
|
120
|
+
exit
|
121
|
+
|
114
122
|
(puts USAGE; exit) if !ARGV[1].nil? # TODO: manual dir as arg1
|
115
123
|
z = Ztrening.new
|
116
124
|
if !z.in_zaddir?
|
data/lib/ztrening.rb
CHANGED
@@ -7,12 +7,102 @@ class Array
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ZtreningM
|
10
|
-
VERSION = '0.0.4.
|
10
|
+
VERSION = '0.0.4.2'
|
11
|
+
CONFDIR = "~/.ztrening"
|
12
|
+
|
13
|
+
class Lines
|
14
|
+
def initialize(filename=nil)
|
15
|
+
throw "File arg ne smije biti prazan" if filename.nil?
|
16
|
+
throw "File not exist" if !File.exist? filename
|
17
|
+
@file = File.readlines filename
|
18
|
+
@lines = @file.collect{|v| v=v.chop if v.end_with? "\n"; v}
|
19
|
+
@filename = filename
|
20
|
+
end
|
21
|
+
|
22
|
+
def find line
|
23
|
+
@lines.grep line || nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete line
|
27
|
+
@lines.delete line
|
28
|
+
end
|
29
|
+
|
30
|
+
def add line=nil
|
31
|
+
throw "line arg prazan!" if line.nil?
|
32
|
+
if (@lines.grep line)[0]
|
33
|
+
r=0
|
34
|
+
else
|
35
|
+
@lines << line
|
36
|
+
r=1
|
37
|
+
end
|
38
|
+
write!
|
39
|
+
r
|
40
|
+
end
|
41
|
+
|
42
|
+
def lines
|
43
|
+
@lines
|
44
|
+
end
|
45
|
+
|
46
|
+
def write!
|
47
|
+
File.open(@filename,'w'){ |f| f.write "#{@lines.compact.join("\n")}\n" }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class TodoFile
|
52
|
+
def self.add line
|
53
|
+
self.open!
|
54
|
+
r=@todofile.add line
|
55
|
+
if r==0
|
56
|
+
puts "Linija vec postoji!"
|
57
|
+
elsif r==1
|
58
|
+
puts "Dodano!"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.delete line
|
63
|
+
self.open!
|
64
|
+
if @todofile.find(line).empty?
|
65
|
+
puts "Nema takve linije!"
|
66
|
+
else
|
67
|
+
@todofile.delete line
|
68
|
+
@todofile.write!
|
69
|
+
puts "Entry deleted!"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.list
|
74
|
+
self.open!
|
75
|
+
r=@todofile.lines.join "\n"
|
76
|
+
if r.empty?
|
77
|
+
"TODO list is empty!"
|
78
|
+
else r end
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
def self.lines
|
83
|
+
@todofile.lines
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.open! mode=nil
|
87
|
+
todo_file = File.expand_path File.join CONFDIR, 'todo.txt'
|
88
|
+
if !File.exist? todo_file
|
89
|
+
FileUtils.touch todo_file
|
90
|
+
end
|
91
|
+
@todofile = Lines.new todo_file
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class ConfDir
|
96
|
+
def self.create_if_ne
|
97
|
+
if !File.directory? File.expand_path CONFDIR
|
98
|
+
FileUtils.mkdir File.expand_path CONFDIR
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
11
102
|
|
12
103
|
class Ztrening
|
13
104
|
def initialize(*opts)
|
14
105
|
@list_fname = 'ztlista.txt'
|
15
|
-
# @cmd_dwl = "wget -q http://z-trening.com/training.php\?all_tasks\=1 -O #{@list_fname}"
|
16
106
|
@dwl_link = "z-trening.com|/training.php\?all_tasks\=1"
|
17
107
|
@link_base = 'http://z-trening.com/tasks.php?show_task=_ID_'
|
18
108
|
@ztdir_fname = '.ztconf' # bolje ztdata; file sa conf vars
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ztrening
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 91
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 4
|
10
|
-
-
|
11
|
-
version: 0.0.4.
|
10
|
+
- 2
|
11
|
+
version: 0.0.4.2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- BKrsta
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-08-
|
19
|
+
date: 2010-08-18 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|