Class: RubyNews::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/rubynews/tool.rb

Instance Method Summary collapse

Instance Method Details



49
50
51
# File 'lib/rubynews/tool.rb', line 49

def banner
  puts "Welcome to Ruby News v#{VERSION}   (#{News.channels.count} Channels, #{News.items.count} Items)"
end

#listObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rubynews/tool.rb', line 53

def list
  date = Date.today
  empty_week_counter = 0

  loop do
    week        = date.cweek
    year        = date.year
    week_start  = Date.commercial( year, week, 1 )
    week_end    = Date.commercial( year, week, 7 )

    count       = News.week(week, year).count
    if count == 0
      empty_week_counter += 1
    else
      empty_week_counter = 0
    end

    print
    print "Week #{week}/#{year} - "
    print "#{week_start.format('Mon, 02 Jan')} to "
    print "#{week_end.format('Mon, 02 Jan')}   "
    print "(#{count} Items)"
    print "\n"


    last_day  = nil
    last_host = nil    ## todo/fix: change to last_source_title or something??

    News.week(week, year).each do |item|
      if last_day != item.date.day
        puts
        print "  #{item.date.format( 'Mon, 02 Jan' )}   "
        print ">> #{item.feed.title || URI(item.feed.feed_url).host} <<"
        print "\n"
      elsif last_host != (item.feed.title || URI(item.feed.feed_url).host)
        print "                "
        ## note: print feed title and if missing fallback to feed host (from url) 
        ##  todo/fix:  check for feed location - if present add with @ !!!!
        print ">> #{item.feed.title || URI(item.feed.feed_url).host} <<"
        print "\n"
      else
      end

      puts "    #{item.title}"

      last_day  = item.date.day
      last_host = item.feed.title || URI(item.feed.feed_url).host
    end

    if count > 0 || empty_week_counter > 10
      puts
      print ">> Press space for more; press any key to quit. <<"
      ch = STDIN.getch
      print "\r"

      empty_week_counter = 0

      break if ch != ' '
    end
    date = week_start-1
  end

  print "                                                   "
  print "\n"

  puts ">> TIP: Type > rubyconf < to list all upcoming ruby conferences & camps in #{Date.today.year}. <<"
  puts
  puts "Bye"
end

#updateObject



6
7
8
9
10
11
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
37
38
39
40
41
42
43
44
45
46
# File 'lib/rubynews/tool.rb', line 6

def update
  News.subscribe(
    'http://www.ruby-lang.org/en/feeds/news.rss',     # Ruby Lang News
    'http://www.jruby.org/atom.xml',                  # JRuby Lang News
    'http://blog.rubygems.org/atom.xml',              # RubyGems News
    'http://bundler.io/blog/feed.xml',                # Bundler News
    'https://www.ruby-toolbox.com/blog.rss',          # Ruby Toolbox News
    'https://idiosyncratic-ruby.com/feed.xml',        # Idiosyncratic Ruby
    'http://weblog.rubyonrails.org/feed/atom.xml',    # Ruby on Rails News
    'http://sinatrarb.com/feed.xml',                  # Sinatra News
    'https://dry-rb.org/feed.xml',                    # DRY News
    'https://hanamirb.org/atom.xml',                  # Hanami News
    'http://jekyllrb.com/feed.xml',                   # Jekyll News
    'http://feeds.feedburner.com/jetbrains_rubymine?format=xml',  # RubyMine IDE News
    'https://blog.phusion.nl/rss/',                   # Phusion News
    'https://rubyinstaller.org/feed.xml',             # Ruby Installer for Windows News

    'http://planetruby.github.io/calendar/feed.xml',  # Ruby Conferences & Camps News
    'https://rubytogether.org/news.xml',              # Ruby Together News
    'https://foundation.travis-ci.org/feed.xml',      # Travis Foundation News
    'https://railsgirlssummerofcode.org/blog.xml',    # Rails Girls Summer of Code News

     ## Ruby People ++ Personal Blog / Website
    'http://blog.zenspider.com/atom.xml',          # Ryan Davis @ Seattle › Washington › United States
    'http://tenderlovemaking.com/atom.xml',        # Aaron Patterson @ Seattle › Washington › United States
    'http://blog.headius.com/feed.xml',            # Charles Nutter @ Richfield › Minnesota › United States
    'http://www.schneems.com/feed.xml',            # Richard Schneeman @ Austin › Texas › United States
    'https://developers.redhat.com/blog/author/vnmakarov/feed/',  # Vladimir Makarov @ Toronto › Canada

    'https://eregon.me/blog/feed.xml',             # Benoit Daloze @ Zürich › Switzerland
    'https://gettalong.org/posts.atom',            # Thomas Leitner @ Vienna • Wien › Austria
    'https://rubytuesday.katafrakt.me/feed.xml',   # Paweł Świątkowski @ Kraków, Poland
    'https://solnic.codes/feed/',                  # Piotr Solnica @ Kraków › Poland
    'https://zverok.github.io/feed.xml',           # Victor Shepelev @ Kharkiv › Ukraine

    'http://samsaffron.com/posts.rss',             # Sam Saffron @ Sydney › Australia
    'https://www.rubypigeon.com/feed.xml',         # Tom Dalling @ Melbourne› Australia
    )

  News.update
end