class Gigawatt::Commands::Status

Attributes

options[RW]

Public Class Methods

new(settings, options) click to toggle source
# File lib/gigawatt/commands/status.rb, line 28
def initialize(settings, options)
  @settings = settings
  @options = options

  @access_key = OAuth.token(@settings.access_key)
  @cache = Cache.new(settings, @access_key)

  @project = Gigawatt::ProjectFile.new.project
end
run!(settings) click to toggle source
# File lib/gigawatt/commands/status.rb, line 6
      def self.run!(settings)
        options = Trollop::options do
          banner <<-EOS
88 Miles Command line application - http://88miles.net

Get status about the linked project

Usage:
  88miles status [options]

options:
          EOS

          opt :sync, "Sync the data from the server first. Uses the cache if false", :type => :flag
          opt :foreground, "Don't exit - just refresh the timer", :type => :flag
          opt :time, "Only return the time", :type => :flag
        end

        instance = self.new(settings, options)
        return instance.get_settings
      end

Public Instance Methods

get_settings() click to toggle source
# File lib/gigawatt/commands/status.rb, line 38
def get_settings
  unless @project
    say("No project found.")
    return NO_PROJECT_EXIT_CODE
  end

  if @options[:sync]
    sync = Gigawatt::Commands::Sync.new(@settings, @options)
    begin
      sync.sync
      sync.sync_current
    rescue OAuth2::Error => e
      say "Access to your 88 Miles may have been revoked. Please run <%= color('88miles setup', BOLD) %> again."
      return INVALID_OAUTH_TOKEN_EXIT_CODE
    end
  end

  if @options[:foreground]
    while(1)
      print_status
      sleep(1)
    end
    print "\n"
  else
    print_status
    print "\n"
  end

  return OK_EXIT_CODE
end
print_status() click to toggle source
to_clock_s(time, show_seconds = false) click to toggle source
# File lib/gigawatt/commands/status.rb, line 92
def to_clock_s(time, show_seconds = false)
  hour = (time.abs / 3600).floor
  minute = (time.abs / 60 % 60).floor
  seconds = (time.abs % 60).floor if show_seconds

  return (time != 0 && (time / time.abs) == -1 ? "-" : "") + hour.to_s.rjust(2, '0') + ":" + minute.to_s.rjust(2, '0') + (show_seconds ? ":" + seconds.to_s.rjust(2, '0') : '')
end