ztrening 0.0.2 → 0.0.3
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/History.txt +6 -0
- data/Manifest.txt +0 -1
- data/bin/zt +62 -14
- data/lib/ztrening.rb +30 -17
- metadata +3 -4
- data/lib/zt/cli.rb +0 -42
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/bin/zt
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# Created on 2010-6-30.
|
4
3
|
# Copyright (c) 2010. All rights reserved.
|
5
4
|
|
6
5
|
require 'rubygems'
|
7
6
|
require File.expand_path(File.dirname(__FILE__) + "/../lib/ztrening")
|
8
|
-
# require "zt/cli"
|
9
|
-
|
10
|
-
# Zt::CLI.execute(STDOUT, ARGV)
|
11
7
|
|
12
8
|
include ZtreningM
|
13
9
|
|
14
10
|
USAGE = <<EOS
|
15
11
|
usage: zt.rb [refresh, list, find, open]
|
16
12
|
find [string]
|
17
|
-
open [filename]
|
13
|
+
open [filename] => file mora imati '// zt [ime zadatka]' na 1. liniji
|
14
|
+
-h, --help
|
18
15
|
EOS
|
19
16
|
|
20
17
|
@imefromfile_regex = /\/\/ zt (.*)/
|
@@ -27,11 +24,12 @@ end
|
|
27
24
|
|
28
25
|
|
29
26
|
if ARGV[0] == 'refresh'
|
30
|
-
z = Ztrening.new
|
27
|
+
z = Ztrening.new :web
|
31
28
|
puts 'New list downloaded'
|
32
29
|
elsif ARGV[0] == 'open' && ARGV[1]
|
33
30
|
# TODO: maknuti gore const file regex
|
34
31
|
z = Ztrening.new
|
32
|
+
|
35
33
|
if File.exists? ARGV[1]
|
36
34
|
file = File.new(ARGV[1], 'r')
|
37
35
|
else
|
@@ -44,14 +42,61 @@ elsif ARGV[0] == 'open' && ARGV[1]
|
|
44
42
|
puts "Prva linija ne sadrzi ime zadatka"
|
45
43
|
exit
|
46
44
|
else
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
str = prvalin.sub(/\/\/ /, '').sub(/\n/, '')
|
46
|
+
byid=0
|
47
|
+
regex_wime = /^zt /
|
48
|
+
regex_wid = /^ZT /
|
49
|
+
|
50
|
+
if str.match(regex_wime)
|
51
|
+
str.sub!(regex_wime, '')
|
52
|
+
ime = str
|
53
|
+
z.find_by_name(ime)
|
54
|
+
elsif str.match(regex_wid)
|
55
|
+
str.sub!(regex_wid, '')
|
56
|
+
id = str
|
57
|
+
byid=1
|
58
|
+
z.find_by_id(id.to_a)
|
59
|
+
end
|
60
|
+
|
61
|
+
if !str.match(/^./)
|
62
|
+
puts "Datoteka ne sadrzi (ispravno) ime ili ID!"
|
63
|
+
exit
|
64
|
+
end
|
65
|
+
|
66
|
+
if z.lista.nil? or z.lista.empty?
|
67
|
+
hh = if ime.nil?; "im ID-om" else "im imenom" end
|
68
|
+
puts "Nema zadataka s takv#{hh}"
|
69
|
+
end
|
70
|
+
|
71
|
+
hh = if ime.nil?; "ID" else "ime" end
|
72
|
+
puts "Oznaka zadatka iz datoteke: #{str} (#{hh})"
|
73
|
+
|
74
|
+
puts "cnt: #{z.lista.count}"
|
75
|
+
# if z.lista.count > 1
|
76
|
+
# puts "Postoji vise zadataka koji sadrze '#{ime}';"
|
77
|
+
# puts "Odaberi jedan:"
|
78
|
+
# limit, ok = 10, 1
|
79
|
+
# if z.lista.count > limit
|
80
|
+
# puts "Broj nadjenih zadataka prelazi limit (#{limit}) !"
|
81
|
+
# exit
|
82
|
+
# end
|
83
|
+
# z.lista.each_with_index { |l,idx| printf "%4s: %s\n", idx+1, l[1] }
|
84
|
+
# while ok > 0
|
85
|
+
# print " > "; STDOUT.flush
|
86
|
+
# id = STDIN.gets.chomp.to_i
|
87
|
+
# if id.nil? or id == '' or !id.is_a?(Integer)
|
88
|
+
# puts " ?? err 1"
|
89
|
+
# end
|
90
|
+
# # id -= 1
|
91
|
+
# if !(1..(z.lista.count)).include?(id)
|
92
|
+
# puts "izvan rangea!"; ok=1
|
93
|
+
# else ok=0 end
|
94
|
+
# end
|
95
|
+
# puts "Otvaram zadatak: #{z.lista[id.to_i-1][1]}"
|
96
|
+
# z.open id-1
|
97
|
+
# else
|
98
|
+
# z.open :name => ime | :id => id
|
99
|
+
z.open id
|
55
100
|
end
|
56
101
|
elsif ARGV[0] == 'find'
|
57
102
|
if ARGV[1]
|
@@ -70,4 +115,7 @@ elsif ARGV[0] == 'find'
|
|
70
115
|
elsif ARGV[0] == 'list'
|
71
116
|
z = Ztrening.new
|
72
117
|
z.lista_txt
|
118
|
+
else
|
119
|
+
puts USAGE
|
120
|
+
exit
|
73
121
|
end
|
data/lib/ztrening.rb
CHANGED
@@ -6,7 +6,7 @@ class Array
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module ZtreningM
|
9
|
-
VERSION = '0.0.
|
9
|
+
VERSION = '0.0.3'
|
10
10
|
|
11
11
|
class Ztrening
|
12
12
|
def initialize(*opts)
|
@@ -36,25 +36,38 @@ module ZtreningM
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def find(str)
|
39
|
-
puts "Lista je prazna!" if @lista.nil?
|
40
|
-
ll
|
41
|
-
@lista.each
|
42
|
-
if e[1]
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
@lista = []
|
39
|
+
puts "Lista je prazna!" if @lista.nil? or @lista.empty?
|
40
|
+
ll=[]
|
41
|
+
@lista.each { |e|
|
42
|
+
ll << e if e[1].match(/#{str}/)
|
43
|
+
}
|
47
44
|
@lista = ll
|
48
45
|
end
|
49
46
|
|
47
|
+
def find_by_name(str)
|
48
|
+
puts "Lista je prazna! (find_uniq)" if @lista.nil? or @lista.empty?
|
49
|
+
ll=[]
|
50
|
+
@lista.each { |e| ll << e if e[1] == str }
|
51
|
+
@lista = ll
|
52
|
+
puts "find_by_name lista cnt: #{@lista.count}"
|
53
|
+
end
|
54
|
+
|
50
55
|
def find_by_id(id)
|
51
|
-
|
56
|
+
puts "Lista je prazna! (find_by_id)" if @lista.nil? or @lista.empty?
|
57
|
+
# puts "find_by_id lista cnt begin: #{@lista.count}"
|
58
|
+
ll=[]
|
59
|
+
@lista.each { |e| ll << e if e[0].match /#{id}/ }
|
60
|
+
@lista = ll
|
61
|
+
# puts "find_by_id lista cnt return: #{@lista.count}"
|
52
62
|
end
|
53
63
|
|
54
|
-
def open
|
55
|
-
puts "Lista je prazna!" if @lista.nil? || @lista.empty?
|
64
|
+
def open(arg=-1)
|
65
|
+
puts "Lista je prazna! (open)" if @lista.nil? || @lista.empty?
|
56
66
|
if @lista.count == 1
|
57
67
|
system "open #{link @lista[0][0]}"
|
68
|
+
elsif arg!=-1
|
69
|
+
# puts "arg u open(): #{arg}, #{arg.class}"
|
70
|
+
system "open #{link(@lista[arg][0])}"
|
58
71
|
else
|
59
72
|
puts "Lista ne sadrzi 1 zadatak!"
|
60
73
|
end
|
@@ -64,6 +77,10 @@ module ZtreningM
|
|
64
77
|
@lista
|
65
78
|
end
|
66
79
|
|
80
|
+
# def lista=(l)
|
81
|
+
# @lista=l
|
82
|
+
# end
|
83
|
+
|
67
84
|
def lista_txt
|
68
85
|
puts 'Zadatci:'
|
69
86
|
@lista.each { |l| puts "Zadatak: #{l[1]}" }
|
@@ -105,10 +122,6 @@ module ZtreningM
|
|
105
122
|
end
|
106
123
|
|
107
124
|
def cmd
|
108
|
-
# return <<EOS
|
109
|
-
# cat #{@list_fname} | grep ' <a href="tasks.php?show_task=.*>' | sed 's/.* //g' | \
|
110
|
-
# grep -o '[0-9]\\{10\\}.*' | sed -e 's/">/ - /g' -e 's:</a></TD>::g'
|
111
|
-
# EOS
|
112
125
|
return <<EOS
|
113
126
|
cat #{@list_fname} | grep ' <a href="tasks.php?show_task=.*>' | sed 's/.* //g' | \
|
114
127
|
grep -o '[0-9]\\{10\\}.*' | sed -e 's/">/ - /g' -e 's:</a></TD>::g'
|
@@ -116,4 +129,4 @@ EOS
|
|
116
129
|
end
|
117
130
|
|
118
131
|
end
|
119
|
-
end
|
132
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ztrening
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- BKrsta
|
@@ -66,7 +66,6 @@ files:
|
|
66
66
|
- README.rdoc
|
67
67
|
- Rakefile
|
68
68
|
- bin/zt
|
69
|
-
- lib/zt/cli.rb
|
70
69
|
- lib/ztrening.rb
|
71
70
|
- script/console
|
72
71
|
- script/destroy
|
data/lib/zt/cli.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
|
3
|
-
module Zt
|
4
|
-
class CLI
|
5
|
-
def self.execute(stdout, arguments=[])
|
6
|
-
|
7
|
-
# NOTE: the option -p/--path= is given as an example, and should be replaced in your application.
|
8
|
-
|
9
|
-
options = {
|
10
|
-
:path => '~'
|
11
|
-
}
|
12
|
-
mandatory_options = %w( )
|
13
|
-
|
14
|
-
parser = OptionParser.new do |opts|
|
15
|
-
opts.banner = <<-BANNER.gsub(/^ /,'')
|
16
|
-
This application is wonderful because...
|
17
|
-
|
18
|
-
Usage: #{File.basename($0)} [options]
|
19
|
-
|
20
|
-
Options are:
|
21
|
-
BANNER
|
22
|
-
opts.separator ""
|
23
|
-
opts.on("-p", "--path PATH", String,
|
24
|
-
"This is a sample message.",
|
25
|
-
"For multiple lines, add more strings.",
|
26
|
-
"Default: ~") { |arg| options[:path] = arg }
|
27
|
-
opts.on("-h", "--help",
|
28
|
-
"Show this help message.") { stdout.puts opts; exit }
|
29
|
-
opts.parse!(arguments)
|
30
|
-
|
31
|
-
if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
|
32
|
-
stdout.puts opts; exit
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
path = options[:path]
|
37
|
-
|
38
|
-
# do stuff
|
39
|
-
stdout.puts "To update this executable, look in lib/zt/cli.rb"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|