class Haora::Service

Attributes

workbook[R]

Public Class Methods

for(file_name) click to toggle source
# File lib/haora.rb, line 24
def self.for(file_name)
  Service.new(file_name)
end
new(file_name) click to toggle source
# File lib/haora.rb, line 76
def initialize(file_name)
  @workbook = open_workbook(file_name)
end

Public Instance Methods

add_task(params) click to toggle source
# File lib/haora.rb, line 28
def add_task(params)
  write do
    AddTaskCommand
        .with(@workbook)
        .params(params)
        .execute
  end
end
finish(params) click to toggle source
# File lib/haora.rb, line 37
def finish(params)
  write do
    FinishCommand
        .with(@workbook)
        .params(params)
        .execute
  end
end
list(params) click to toggle source
# File lib/haora.rb, line 46
def list(params)
  read do
    ListCommand
        .with(@workbook)
        .params(params)
        .execute
  end
end

Private Instance Methods

close() click to toggle source
# File lib/haora.rb, line 89
def close
  File.open(@workbook.path, 'w') do |file|
    export(@workbook, file)
  end
end
open_workbook(file_name) click to toggle source
# File lib/haora.rb, line 80
def open_workbook(file_name)
  File.ensure_exist file_name
  File.open(file_name, 'r') do |file|
    workbook = import(file)
    workbook.path = file.path
    workbook
  end
end
read() { || ... } click to toggle source
# File lib/haora.rb, line 66
def read
  begin
    yield
  rescue RuntimeError => error
    error.message
  end
end
write() { || ... } click to toggle source
# File lib/haora.rb, line 57
def write
  begin
    yield
    close
  rescue RuntimeError => error
    error.message
  end
end