Class: ZtreningM::Ztrening
- Inherits:
-
Object
- Object
- ZtreningM::Ztrening
- Defined in:
- lib/ztrening.rb
Instance Method Summary collapse
- #find(str) ⇒ Object
- #find_by_id(id) ⇒ Object
-
#initialize(*opts) ⇒ Ztrening
constructor
A new instance of Ztrening.
- #lista ⇒ Object
- #lista_as_html(*args) ⇒ Object
- #lista_txt ⇒ Object
- #open ⇒ Object
Constructor Details
#initialize(*opts) ⇒ Ztrening
Returns a new instance of Ztrening.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ztrening.rb', line 12 def initialize(*opts) @list_fname = 'lista.txt' @cmd_dwl = "wget -q http://z-trening.com/training.php\?all_tasks\=1 -O #{@list_fname}" @link_base = 'http://z-trening.com/tasks.php?show_task=_ID_' @lista ||= [] @opts = opts.moj_keys execerrmsg = "'exec' error! Aborting ..." if !@opts[:web].nil? web execout = exec (puts execerrmsg; exit) if execout.nil? || execout.empty? @lista = parse(execout) else if !File.exists? @list_fname puts "Datoteka #{@list_fname} ne postoji, skidam s weba ..." web end execout = exec (puts execerrmsg; exit) if execout.nil? || execout.empty? @lista = parse(execout) end end |
Instance Method Details
#find(str) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ztrening.rb', line 38 def find(str) puts "Lista je prazna!" if @lista.nil? || @lista.empty? ll ||= [] @lista.each do |e| if e[1] =~ /#{str}/ ll << e end end @lista = [] @lista = ll end |
#find_by_id(id) ⇒ Object
50 51 52 |
# File 'lib/ztrening.rb', line 50 def find_by_id(id) @lista.detect { |e| id == e[0] } end |
#lista ⇒ Object
63 64 65 |
# File 'lib/ztrening.rb', line 63 def lista @lista end |
#lista_as_html(*args) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ztrening.rb', line 72 def lista_as_html(*args) opts = args.moj_keys puts '<ul>' if opts[:li] puts '<b>Zadatci:</b>' if opts[:naslov] @lista.each { |l| print '<li>' if opts[:li] print "<a href='#{link(l[0])}'>#{l[1]}</a>" puts if !opts[:li] print "</li>\n" if opts[:li] } puts '</ul>' if opts[:li] end |
#lista_txt ⇒ Object
67 68 69 70 |
# File 'lib/ztrening.rb', line 67 def lista_txt puts 'Zadatci:' @lista.each { |l| puts "Zadatak: #{l[1]}" } end |
#open ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/ztrening.rb', line 54 def open puts "Lista je prazna!" if @lista.nil? || @lista.empty? if @lista.count == 1 system "open #{link @lista[0][0]}" else puts "Lista ne sadrzi 1 zadatak!" end end |