Top Level Namespace

Defined Under Namespace

Modules: Barometer Classes: App

Constant Summary collapse

KEY_FILE =

file where API keys are stored

File.expand_path(File.join('~', '.barometer'))
BAROMETER_VERSION =
'0.7.2'

Instance Method Summary collapse

Instance Method Details

#blankObject



277
278
279
# File 'bin/barometer', line 277

def blank
  puts
end

#bug_key_messageObject



464
465
466
467
468
469
470
471
472
473
# File 'bin/barometer', line 464

def bug_key_message
  puts
  puts "MISSING KEYS !!!"
  puts "Please update the key_file '#{KEY_FILE}' with your weather_bug api key"
  puts "Get it here: ???"
  puts "Then, add these lines to the file:"
  puts "weather_bug:"
  puts "  code: API_CODE"
  puts
end

#div(char = "#") ⇒ Object



264
265
266
# File 'bin/barometer', line 264

def div(char="#")
  puts char*50
end

#pretty_current(c) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'bin/barometer', line 358

def pretty_current(c)
  return unless c
  section("CURRENT", 2) do
    pretty_hash({
      "Measured at" => c.current_at, "Updated at" => c.updated_at,
      "Humidity" => c.humidity, "Icon" => c.icon,
      "Condition" => c.condition, "Temperature" => c.temperature,
      "Dew Point" => c.dew_point, "Heat Index" => c.heat_index,
      "Pressure" => c.pressure, "Visibility" => c.visibility,
      "Wind Chill" => c.wind_chill })
    pretty_hash({ "Wind" => c.wind, "Wind Direction" => c.wind.direction,
      "Wind Degrees" => c.wind.degrees }) if c.wind
    pretty_hash({ "Sun Rise" => c.sun.rise, "Sun Set" => c.sun.set }) if c.sun
  end
end

#pretty_forecast(f) ⇒ Object



374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'bin/barometer', line 374

def pretty_forecast(f)
  return unless f
  section("FOR: #{f.date}", 3) do
    pretty_hash({
      "Valid From" => f.valid_start_date.to_s(true), 
      "Valid Until" => f.valid_end_date.to_s(true),
      "Icon" => f.icon, "Description" => f.description,
      "Condition" => f.condition, "High" => f.high,
      "Low" => f.low, "POP" => f.pop, "Humidity" => f.humidity })
    pretty_hash({ "Wind" => f.wind, "Wind Direction" => f.wind.direction,
      "Wind Degrees" => f.wind.degrees }) if f.wind
    pretty_hash({ "Sun Rise" => f.sun.rise, "Sun Set" => f.sun.set }) if f.sun
  end
end

#pretty_forecasts(forecasts) ⇒ Object



389
390
391
392
393
394
395
396
397
# File 'bin/barometer', line 389

def pretty_forecasts(forecasts)
  return unless forecasts
  section("FORECAST(s)", 3, false) do
    blank
    forecasts.each do |forecast|
      pretty_forecast(forecast)
    end
  end
end

#pretty_hash(hash) ⇒ Object



286
287
288
289
# File 'bin/barometer', line 286

def pretty_hash(hash)
  return unless hash.is_a?(Hash)
  hash.each { |k,v| value(k,v) }
end

#pretty_info(w) ⇒ Object



428
429
430
431
432
433
# File 'bin/barometer', line 428

def pretty_info(w)
  title("INFO", 1)
  value("GitHub", "http://github.com/attack/barometer")
  value("Barometer Version", BAROMETER_VERSION)
  value("Total Time", "#{(w.end_at - w.start_at)} s")
end

#pretty_location(l) ⇒ Object



326
327
328
329
330
331
332
333
334
335
336
# File 'bin/barometer', line 326

def pretty_location(l)
  return unless l
  section("LOCATION", 2) do
    pretty_hash({
      "ID" => l.id, "Name" => l.name,
      "City" => l.city, "State Name" => l.state_name,
      "State Code" => l.state_code, "Country" => l.country,
      "Country Code" => l.country_code, "Zip Code" => l.zip_code,
      "Latitude" => l.latitude, "Longitude" => l.longitude })
  end
end

#pretty_measurement(m) ⇒ Object



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'bin/barometer', line 399

def pretty_measurement(m)
  return unless m
  section(m.source.to_s, 1) do
    pretty_hash({
      "Measured At" => m.measured_at,
      "Source" => m.source, "Time Stamp" => m.utc_time_stamp,
      "Metric" => m.metric?, "Success" => m.success?,
      "Service Time" => "#{(m.end_at - m.start_at)} s" })
  end
  section("MODIFIED QUERY", 2) do
    pretty_hash({ "Query" => m.query, "Format" => m.format })
  end
  pretty_location(m.location)
  pretty_station(m.station)
  pretty_timezone(m.timezone)
  pretty_current(m.current)
  pretty_forecasts(m.forecast)
end

#pretty_measurements(w) ⇒ Object



418
419
420
421
422
423
424
425
426
# File 'bin/barometer', line 418

def pretty_measurements(w)
  return unless w
  section("MEASUREMENTS", 1) do
    blank
    w.measurements.each do |m|
      pretty_measurement(m)
    end
  end
end

#pretty_output(barometer) ⇒ Object



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'bin/barometer', line 435

def pretty_output(barometer)
  weather = barometer.weather
  if weather
    div
    puts "#"
    puts "#  #{weather.default.location.name || barometer.query.q}"
    puts "#"
    div
    blank
    pretty_summary(weather)
    pretty_query(barometer.query)
    pretty_measurements(weather)
    pretty_info(weather)
    div("-")
  end
end

#pretty_query(q) ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'bin/barometer', line 308

def pretty_query(q)
  return unless q
  section("ORIGINAL QUERY", 1) do
    pretty_hash({
      "Query" => q.q, "Format" => q.format,
      "Country Code" => q.country_code })
  end
  if q.geo
    section("GEO", 2) do
      pretty_hash({
        "Address" => q.geo.address, "Query" => q.geo.query,
        "Locality" => q.geo.locality, "Region" => q.geo.region,
        "Country" => q.geo.country, "Country Code" => q.geo.country_code,
        "Latitude" => q.geo.latitude, "Longitude" => q.geo.longitude })
    end
  end
end

#pretty_station(s) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
# File 'bin/barometer', line 338

def pretty_station(s)
  return unless s
  section("STATION", 2) do
    pretty_hash({
      "ID" => s.id, "Name" => s.name,
      "City" => s.city, "State Name" => s.state_name,
      "State Code" => s.state_code, "Country" => s.country,
      "Country Code" => s.country_code, "Zip Code" => s.zip_code,
      "Latitude" => s.latitude, "Longitude" => s.longitude })
  end
end

#pretty_summary(s) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'bin/barometer', line 291

def pretty_summary(s)
  return unless s
  section("AVERAGES") do
    pretty_hash({
      "humidity" => s.humidity.to_i, "temperature" => s.temperature,
      "wind" => s.wind, "pressure" => s.pressure,
      "dew_point" => s.dew_point, "heat_index" => s.heat_index,
      "wind_chill" => s.wind_chill, "visibility" => s.visibility })
  end
  section("SUMMARY#{ " (@ #{@options.at})" if @options.at }") do
    pretty_hash({
      "day?" => s.day?(@options.at), "sunny?" => s.sunny?(@options.at),
      "windy?" => s.windy?(@options.at, @options.metric ? @options.windy_m : @options.windy_i),
      "wet?" => s.wet?(@options.at, @options.pop) })
  end
end

#pretty_timezone(t) ⇒ Object



350
351
352
353
354
355
356
# File 'bin/barometer', line 350

def pretty_timezone(t)
  return unless t
  section("TIMEZONE", 2) do
    pretty_hash({ "Long" => t.full, "Code" => t.code, "DST?" => t.dst?,
      "Now" => t.now(true), "Today" => t.today })
  end
end

#section(title, level = 1, show_blank = true) ⇒ Object



281
282
283
284
# File 'bin/barometer', line 281

def section(title, level=1, show_blank=true)
  @level = level
  title(title, level); yield; blank if show_blank
end

#title(title, level = 1) ⇒ Object



268
269
270
271
# File 'bin/barometer', line 268

def title(title, level=1)
  @level = level
  puts "#{"  " * @level}-- #{title} --"
end

#value(title, value) ⇒ Object



273
274
275
# File 'bin/barometer', line 273

def value(title, value)
  puts "#{"  " * @level}#{title}: #{value}" unless value.nil?
end

#weather_key_messageObject



452
453
454
455
456
457
458
459
460
461
462
# File 'bin/barometer', line 452

def weather_key_message
  puts
  puts "MISSING KEYS !!!"
  puts "Please update the key_file '#{KEY_FILE}' with your weather api keys"
  puts "Get it here: ???"
  puts "Then, add these lines to the file:"
  puts "weather:"
  puts "  partner: PARTNER_KEY"
  puts "  license: LICENSE_KEY"
  puts
end

#y(value) ⇒ Object



260
261
262
# File 'bin/barometer', line 260

def y(value)
  value ? "yes" : "no"
end