Top Level Namespace
Defined Under Namespace
Modules: Barometer Classes: App
Constant Summary collapse
- KEY_FILE =
file where API keys are stored
File.(File.join('~', '.barometer'))
Instance Method Summary collapse
- #blank ⇒ Object
- #bug_key_message ⇒ Object
- #div(char = "#") ⇒ Object
- #pretty_current(c) ⇒ Object
- #pretty_forecast(f) ⇒ Object
- #pretty_forecasts(forecasts) ⇒ Object
- #pretty_hash(hash) ⇒ Object
- #pretty_info(w) ⇒ Object
- #pretty_location(l) ⇒ Object
- #pretty_measurement(m) ⇒ Object
- #pretty_measurements(w) ⇒ Object
- #pretty_output(barometer) ⇒ Object
- #pretty_query(q) ⇒ Object
- #pretty_station(s) ⇒ Object
- #pretty_summary(s) ⇒ Object
- #pretty_timezone(t) ⇒ Object
- #section(title, level = 1, show_blank = true) ⇒ Object
- #title(title, level = 1) ⇒ Object
- #value(title, value) ⇒ Object
- #y(value) ⇒ Object
Instance Method Details
#blank ⇒ Object
243 244 245 |
# File 'bin/barometer', line 243 def blank puts end |
#bug_key_message ⇒ Object
418 419 420 421 422 423 424 425 426 427 |
# File 'bin/barometer', line 418 def 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
230 231 232 |
# File 'bin/barometer', line 230 def div(char="#") puts char*50 end |
#pretty_current(c) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'bin/barometer', line 324 def pretty_current(c) return unless c section("CURRENT", 2) do pretty_hash({ "Measured at" => c.current_at, "Updated at" => c.updated_at.to_s(true), "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
340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'bin/barometer', line 340 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
355 356 357 358 359 360 361 362 363 |
# File 'bin/barometer', line 355 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
252 253 254 255 |
# File 'bin/barometer', line 252 def pretty_hash(hash) return unless hash.is_a?(Hash) hash.each { |k,v| value(k,v) } end |
#pretty_info(w) ⇒ Object
394 395 396 397 398 399 |
# File 'bin/barometer', line 394 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
292 293 294 295 296 297 298 299 300 301 302 |
# File 'bin/barometer', line 292 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
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'bin/barometer', line 365 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
384 385 386 387 388 389 390 391 392 |
# File 'bin/barometer', line 384 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
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'bin/barometer', line 401 def pretty_output() weather = .weather if weather div puts "#" puts "# #{weather.default.location.name || barometer.query.q}" puts "#" div blank pretty_summary(weather) pretty_query(.query) pretty_measurements(weather) pretty_info(weather) div("-") end end |
#pretty_query(q) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'bin/barometer', line 274 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
304 305 306 307 308 309 310 311 312 313 314 |
# File 'bin/barometer', line 304 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
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'bin/barometer', line 257 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?(.at), "sunny?" => s.sunny?(.at), "windy?" => s.windy?(.at, .metric ? .windy_m : .windy_i), "wet?" => s.wet?(.at, .pop) }) end end |
#pretty_timezone(t) ⇒ Object
316 317 318 319 320 321 322 |
# File 'bin/barometer', line 316 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
247 248 249 250 |
# File 'bin/barometer', line 247 def section(title, level=1, show_blank=true) @level = level title(title, level); yield; blank if show_blank end |
#title(title, level = 1) ⇒ Object
234 235 236 237 |
# File 'bin/barometer', line 234 def title(title, level=1) @level = level puts "#{" " * @level}-- #{title} --" end |
#value(title, value) ⇒ Object
239 240 241 |
# File 'bin/barometer', line 239 def value(title, value) puts "#{" " * @level}#{title}: #{value}" unless value.nil? end |
#y(value) ⇒ Object
226 227 228 |
# File 'bin/barometer', line 226 def y(value) value ? "yes" : "no" end |