Class: WhatsOn::Tool

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

Overview

base (shared) tool class

Direct Known Subclasses

BeerFest, Football, PyCon, RubyConf, WhatsOn

Defined Under Namespace

Classes: Config

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV, title: 'Upcoming Events', more_link: nil, show_year: false) ⇒ Tool

Returns a new instance of Tool.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/whatson/tool.rb', line 14

def initialize( args=ARGV,
                title:       'Upcoming Events',
                more_link:   nil,
                show_year:   false
              )
  ## turn down logger (default :debug?)
  LogUtils::Logger.root.level = :info

  @config =  Config.new( title,
                         more_link,
                         show_year )

  @db = EventDb::Memory.new    ## note: use in-memory SQLite database
  args.each do |arg|
    puts "  reading >#{arg}<..."
    @db.read( arg )
  end
end

Instance Method Details

#listObject

note: use list and NOT print (otherwise built-in call to print is recursive and will crash!!!)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
# File 'lib/whatson/tool.rb', line 34

def list   ## note: use list and NOT print (otherwise built-in call to print is recursive and will crash!!!)
  today = Date.today

  puts ''
  puts ''
  puts "#{@config.title}:"
  puts ''

  on = EventDb::Model::Event.live( today )
  on.each do |e|
    print "  NOW ON #{e.current_day(today)}d    "
    print "#{e.title}"
    print " #{e.start_date.year}"     if @config.show_year
    print ", "
    print "#{e.date_fmt} (#{e.days}d) @ #{e.place}"
    print "\n"
  end

  puts '' if on.any?

  ## get next 17 events
  up = EventDb::Model::Event.limit( 17 ).upcoming( today )
  ## pp up.to_sql
  ## pp up

  if up.count > 0
    up.each do |e|
      print "  in #{e.diff_days(today)}d  "
      print "#{e.title}"
      print " #{e.start_date.year}"     if @config.show_year
      print ", "
      print "#{e.date_fmt} (#{e.days}d) @ #{e.place}"
      print "\n"
    end
  else
    puts "  -- No upcoming events found. #{EventDb::Model::Event.count} past event(s) in database. --"
  end

  puts ''

  if @config.more_link
    puts "    More @ #{@config.more_link}"
    puts ''
  end
end