Sha256: 64a8e91c83e4aa502807a353a77e4665456ca415bc485af18f0fa25ce17226cb

Contents?: true

Size: 836 Bytes

Versions: 16

Compression:

Stored size: 836 Bytes

Contents

require 'time'

module TaskManager
  class Task
    attr_accessor :name,
                  :score,
                  :id,
                  :created_at,
                  :started_at,
                  :finished_at

    def initialize(name = nil, score = nil)
      @name  = name
      @score = score
    end

    def self.new_from_node(node)
      task             = Task.new
      task.id          = node['id']
      task.name        = node['name']
      task.score       = node['score']
      task.created_at  = parse_time(node['created_at'])
      task.started_at  = parse_time(node['started_at'])
      task.finished_at = parse_time(node['finished_at'])
      task
    end

    private

    def self.parse_time(string)
      if string && !string.empty?
        Time.parse(string)
      else
        nil
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
task_manager2-0.0.16 lib/task_manager/task.rb
task_manager2-0.0.15 lib/task_manager/task.rb
task_manager2-0.0.14 lib/task_manager/task.rb
task_manager2-0.0.13 lib/task_manager/task.rb
task_manager2-0.0.12 lib/task_manager/task.rb
task_manager2-0.0.11 lib/task_manager/task.rb
task_manager2-0.0.10 lib/task_manager/task.rb
task_manager2-0.0.9 lib/task_manager/task.rb
task_manager2-0.0.8 lib/task_manager/task.rb
task_manager2-0.0.7 lib/task_manager/task.rb
task_manager2-0.0.6 lib/task_manager/task.rb
task_manager2-0.0.5 lib/task_manager/task.rb
task_manager2-0.0.4 lib/task_manager/task.rb
task_manager2-0.0.3 lib/task_manager/task.rb
task_manager2-0.0.2 lib/task_manager/task.rb
task_manager2-0.0.1 lib/task_manager/task.rb