in_our_time 0.4.0 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fba0bd53285d9df8789fb1d0464650ed0c769a41
4
- data.tar.gz: e190622c306d519d8d0a568d629c3f06dc1a5a79
3
+ metadata.gz: 6d431c6acebb6c984ae2866189aa2ff50b3d52c8
4
+ data.tar.gz: 91ea04fe56e4b78e57fc46e4a42350b9f7abafde
5
5
  SHA512:
6
- metadata.gz: 5293b5c48c8a45a2dc7efc464f0ce3c87fdffddd9546e7c4223d339335ef4cd400f8c989fd5c4d227ebd1afd1559a5e72abeea28dfce4287ce9036e8045e0e9a
7
- data.tar.gz: 86738cce5846617abd0f2aac1d019c88eca1a59143792e59c6c7b5137ebcfeaf690fc151ef2334ec9b3d0ebace094170eb1aa381039cc99c96fca7738ce9a239
6
+ metadata.gz: 12cdc3af80022e5a5d50cb34b98d8f2a58431225dde9625b0f2327780892d968c0764e006eee719c8abdd45b42d97b337e9eccf615e84f2fa0e920a23263e12d
7
+ data.tar.gz: a12f8953946ed6708e765f79ed4a9ce1d808f5c63091ef5445f70833678965bfc32e2de3589c5a3cb68ff54ffce9ddf9eca748d476a0b81bfa5d639728ec918b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/lib/iot/iot.rb CHANGED
@@ -51,7 +51,6 @@ class InOurTime
51
51
 
52
52
  def initialize
53
53
  @content = ''
54
- @programs = []
55
54
  @selected = 0
56
55
  clear
57
56
  print "\e[?25h"
@@ -313,7 +312,6 @@ class InOurTime
313
312
  render
314
313
  fetch_uri rss_addresses[count], rss_files[count]
315
314
  end
316
- # iot_puts
317
315
  @config[:last_update] = now
318
316
  save_config
319
317
  end
@@ -323,35 +321,57 @@ class InOurTime
323
321
  end
324
322
 
325
323
  def uniquify_programs
326
- @programs = @programs.uniq{|pr| pr[:title]}
324
+ @programs.uniq!{|pr| pr[:title]}
327
325
  return if @programs.uniq.length == @programs.length
328
326
  print_error_and_delay "Error ensuring Programs unique!"
329
327
  quit 1
330
328
  end
331
329
 
330
+ def tags
331
+ ['title', 'itunes:subtitle',
332
+ 'itunes:summary', 'itunes:duration',
333
+ 'pubDate', 'link']
334
+ end
335
+
336
+ def build_program(bin)
337
+ title = bin[tags[0]].shift.text
338
+ { title: title,
339
+ subtitle: bin[tags[1]].shift.text,
340
+ summary: bin[tags[2]].shift.text,
341
+ duration: bin[tags[3]].shift.text,
342
+ date: bin[tags[4]].shift.text[0..15],
343
+ link: bin[tags[5]].shift.text,
344
+ have_locally: have_locally?(title)
345
+ }
346
+ end
347
+
348
+ def build_programs bin
349
+ bin['title'].size.times do
350
+ @programs << build_program(bin)
351
+ end
352
+ end
353
+
354
+ def item_path name
355
+ "rss/channel/item/#{name}"
356
+ end
357
+
358
+ def clear_programs
359
+ @programs = []
360
+ end
361
+
332
362
  def parse_rss
363
+ clear_programs
333
364
  rss_files.each do |file|
334
365
  @doc = Oga.parse_xml(File.open(file))
335
- titles = @doc.xpath('rss/channel/item/title')
336
- subtitles = @doc.xpath('rss/channel/item/itunes:subtitle')
337
- summarys = @doc.xpath('rss/channel/item/itunes:summary')
338
- durations = @doc.xpath('rss/channel/item/itunes:duration')
339
- dates = @doc.xpath('rss/channel/item/pubDate')
340
- links = @doc.xpath('rss/channel/item/link')
341
-
342
- 0.upto(titles.length - 1) do |idx|
343
- program = {}
344
- program[:title] = titles[idx].text
345
- program[:subtitle] = subtitles[idx].text
346
- program[:summary] = summarys[idx].text
347
- program[:duration] = durations[idx].text
348
- program[:date] = (dates[idx].text)[0..15]
349
- program[:link] = links[idx].text
350
- program[:have_locally] = have_locally?(titles[idx].text)
351
- @programs << program
366
+ bin = {}
367
+ tags.each do |tag|
368
+ bin[tag] = [] if bin[tag].nil?
369
+ bin[tag] = @doc.xpath(item_path(tag))
352
370
  end
371
+ build_programs(bin)
353
372
  end
354
373
  uniquify_programs
374
+ @titles_count = @programs.length
355
375
  end
356
376
 
357
377
  def select_program title
@@ -360,9 +380,8 @@ class InOurTime
360
380
  end
361
381
 
362
382
  def sort_titles
363
- @sorted_titles = []
364
383
  @sorted_titles = @programs.collect { |pr| pr[:title] }
365
- @sorted_titles.sort! unless @sort == :age
384
+ @sorted_titles.sort_by!(&:downcase) unless @sort == :age
366
385
  end
367
386
 
368
387
  def sort_selected title
@@ -383,37 +402,39 @@ class InOurTime
383
402
  redraw
384
403
  end
385
404
 
386
- def list_playing
387
- title = @sorted_titles[@selected]
388
- if title == @playing
389
- list_top
405
+ def list_key
406
+ title = @playing ? @playing : (@sorted_titles[@last_selected || 0])
407
+ if top_or_end?
408
+ list_selected title
390
409
  else
391
- list_selected @playing
410
+ @last_selected = @selected
411
+ list_top_or_end
392
412
  end
393
413
  end
394
414
 
395
- def list_stopped
396
- if @selected == 0
397
- title = @sorted_titles[@last_selected || 0]
398
- list_selected title
399
- else
415
+ def list_top_or_end
416
+ @list_top = @list_top? nil : true
417
+ if @list_top
400
418
  list_top
419
+ else
420
+ list_end
401
421
  end
402
422
  end
403
423
 
404
- def list_key
405
- if @playing
406
- list_playing
407
- else
408
- list_stopped
409
- end
424
+ def top_or_end?
425
+ @selected == 0 || @selected == @titles_count - 1
410
426
  end
411
427
 
412
428
  def list_top
413
429
  @last_selected = @selected
414
- @line_count = 0
415
- @selected = 0
416
- display_list :next_page
430
+ title = @sorted_titles.first
431
+ list_selected title
432
+ end
433
+
434
+ def list_end
435
+ @last_selected = @selected
436
+ title = @sorted_titles.last
437
+ list_selected title
417
438
  end
418
439
 
419
440
  def sort_key
@@ -441,7 +462,7 @@ class InOurTime
441
462
  x = DateTime.strptime("Mon, 20 Jun 2016", '%a, %d %b %Y')
442
463
  y = DateTime.strptime(date, '%a, %d %b %Y')
443
464
  if y < x
444
- return '410' unless @playing == 'Abelard and Heloise'
465
+ return '415' unless @playing == 'Abelard and Heloise'
445
466
  '0' if @playing == 'Abelard and Heloise'
446
467
  else
447
468
  '435'
@@ -586,9 +607,9 @@ class InOurTime
586
607
 
587
608
  def draw_page
588
609
  clear_content
589
- if @line_count <= @sorted_titles.length
610
+ if @line_count <= @titles_count
590
611
  @line_count.upto(@line_count + @page_height - 1) do |idx|
591
- if idx < @sorted_titles.length
612
+ if idx < @titles_count
592
613
  iot_print "> " if(idx == @selected) unless @config[:colour]
593
614
  show_count_maybe idx
594
615
  iot_puts @sorted_titles[idx], @selection_colour if (idx == @selected)
@@ -616,7 +637,7 @@ class InOurTime
616
637
  if @line_count > 0
617
638
  @line_count -= (@page_height * 2)
618
639
  else
619
- @line_count = @sorted_titles.length
640
+ @line_count = @titles_count
620
641
  @selected = @line_count
621
642
  end
622
643
  draw_page
@@ -640,21 +661,20 @@ class InOurTime
640
661
  [] <<
641
662
  " In Our Time Player (#{@version})" <<
642
663
  " " <<
643
- " Play/Stop - X or Enter " <<
644
- " Previous/Next - Down / Up " <<
645
- " Next Page - SPACE " <<
646
- " Sort - S " <<
647
- " Theme Toggle - T " <<
648
- " List Top - L " <<
649
- " Update - U " <<
650
- " Info - I " <<
651
- " Help - H " <<
652
- " Quit - Q " <<
653
- " " <<
654
- " mpg123 Controls: " <<
655
- " Pause/Resume - P " <<
656
- " Forward Skip - F " <<
657
- " Reverse Skip - R " <<
664
+ " Play/Stop - X or Enter " <<
665
+ " Next/Prev - Up / Down " <<
666
+ " Next/Prev Page - Right / Left " <<
667
+ " Sort - S " <<
668
+ " Theme Toggle - T " <<
669
+ " List Top/End - L " <<
670
+ " Update - U " <<
671
+ " Info - I " <<
672
+ " Help - H " <<
673
+ " Quit - Q " <<
674
+ " mpg123 Control " <<
675
+ " Pause/Resume - P / SPACEBAR " <<
676
+ " Forward Skip - F " <<
677
+ " Reverse Skip - R " <<
658
678
  " " <<
659
679
  "Config: #{CONFIG} "
660
680
  end
@@ -807,10 +827,17 @@ class InOurTime
807
827
  end
808
828
 
809
829
  def page_forward
830
+ return unless @line_count < @titles_count
810
831
  @selected = @line_count
811
832
  display_list :next_page
812
833
  end
813
834
 
835
+ def page_back
836
+ @selected = @line_count - @page_height * 2
837
+ @selected = @selected < 0 ? 0 : @selected
838
+ list_selected @sorted_titles[@selected]
839
+ end
840
+
814
841
  def previous
815
842
  @selected -= 1 if @selected > 0
816
843
  if @selected >= @line_count -
@@ -822,6 +849,7 @@ class InOurTime
822
849
  end
823
850
 
824
851
  def next
852
+ return if @selected >= (@titles_count - 1)
825
853
  @selected += 1
826
854
  if @selected <= @line_count - 1
827
855
  redraw
@@ -858,10 +886,9 @@ class InOurTime
858
886
 
859
887
  def do_action ip
860
888
  case ip
861
- when :pause, :forward, :rewind,
862
- :list_key, :page_forward, :previous,
863
- :next, :play, :sort_key, :theme_toggle,
864
- :update_key, :info, :help, :quit_key
889
+ when :pause, :forward, :rewind, :list_key, :page_forward, :page_back,
890
+ :previous, :next, :play, :sort_key, :theme_toggle, :update_key,
891
+ :info, :help, :quit_key
865
892
  self.send ip
866
893
  end
867
894
  end
@@ -53,7 +53,7 @@ class KeyboardEvents
53
53
  @event = :previous if str == "A"
54
54
  @event = :next if str == "B"
55
55
  @event = :page_forward if str == "C"
56
- @event = :previous if str == "D"
56
+ @event = :page_back if str == "D"
57
57
  @mode = :normal
58
58
  else
59
59
  break if @event == :no_event
@@ -75,7 +75,7 @@ class KeyboardEvents
75
75
  when "u",'U'
76
76
  @event = :update_key
77
77
  when ' '
78
- @event = :page_forward
78
+ @event = :pause
79
79
  when "q",'Q', "\u0003", "\u0004"
80
80
  @event = :quit_key
81
81
  when 'p', 'P'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: in_our_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martyn Jago
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-07 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga