Class: MetricTools::SpreadSheet

Inherits:
Object
  • Object
show all
Defined in:
lib/metric_tools/spread_sheet.rb

Overview

Google DocsのSpreadSheetを更新するためのクラス (gem google_driveのラッパーです)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.keyObject

Returns the value of attribute key.



12
13
14
# File 'lib/metric_tools/spread_sheet.rb', line 12

def key
  @key
end

.mailObject

Returns the value of attribute mail.



12
13
14
# File 'lib/metric_tools/spread_sheet.rb', line 12

def mail
  @mail
end

.passwordObject

Returns the value of attribute password.



12
13
14
# File 'lib/metric_tools/spread_sheet.rb', line 12

def password
  @password
end

Class Method Details

.[](i, j) ⇒ Object

インデクサを使用して値にアクセスします



86
87
88
89
90
# File 'lib/metric_tools/spread_sheet.rb', line 86

def [](i, j)
  check_worksheet_seleced_or_raise_error()

  return @worksheet[i+1, j+1]
end

.[]=(i, j, val) ⇒ Object

インデクサを使用して値をアサインします



95
96
97
98
99
# File 'lib/metric_tools/spread_sheet.rb', line 95

def []=(i, j, val)
  check_worksheet_seleced_or_raise_error()

  return @worksheet[i+1, j+1] = val        
end

.change_worksheet_by_title(title) ⇒ Object



52
53
54
55
56
57
# File 'lib/metric_tools/spread_sheet.rb', line 52

def change_worksheet_by_title(title)
  @worksheet = @spread_sheet.worksheet_by_title(title)
  @worksheet = @spread_sheet.add_worksheet(title) if @worksheet.nil?

  @worksheet
end

.check_worksheet_seleced_or_raise_errorObject



123
124
125
# File 'lib/metric_tools/spread_sheet.rb', line 123

def check_worksheet_seleced_or_raise_error
  raise "call 'change_worksheet_by_title' before." if @worksheet.nil?
end

.current_worksheet_titleObject

worksheet



46
47
48
49
50
# File 'lib/metric_tools/spread_sheet.rb', line 46

def current_worksheet_title
  return nil if @worksheet.nil?

  @worksheet.title
end

.heightObject

ワークシートの高さを返します



73
74
75
76
77
78
79
# File 'lib/metric_tools/spread_sheet.rb', line 73

def height
  max = 0
  @worksheet.cells.each do |coord, val|
    max = coord[0] if coord[0] >= max
  end
  max
end

.login(mail, password, key) ⇒ Object

mail, passwordでログインし, 該当するkeyのspreadsheetを編集可能にします



19
20
21
22
23
24
25
26
# File 'lib/metric_tools/spread_sheet.rb', line 19

def (mail, password, key)
  @mail     = mail
  @password = password
  @key      = key

  @session = GoogleDrive.(@mail, @password)
  @spread_sheet = @session.spreadsheet_by_key(@key)
end

.login?Boolean

ログイン状態かどうかを返します

Returns:

  • (Boolean)


40
41
42
# File 'lib/metric_tools/spread_sheet.rb', line 40

def login?
  return !@session.nil? && !@spread_sheet.nil?
end

.logoutObject

ログアウトします



31
32
33
34
35
# File 'lib/metric_tools/spread_sheet.rb', line 31

def logout
  @session = nil
  @spread_sheet = nil
  @worksheet = nil
end

.saveObject

スプレッドシートにここまでの変更を反映します。 saveを呼ぶまでは、実際にスプレッドシートには書き込まれません。



117
118
119
120
121
# File 'lib/metric_tools/spread_sheet.rb', line 117

def save
  check_worksheet_seleced_or_raise_error()

  @worksheet.synchronize
end

.set_value_table(table) ⇒ Object

Tableクラスの内容を、スプレッドシートに書き出します。



104
105
106
107
108
109
110
111
# File 'lib/metric_tools/spread_sheet.rb', line 104

def set_value_table(table)
  check_worksheet_seleced_or_raise_error()

  raise 'can receive Table class only' unless table.kind_of? MetricTools::Table
  table.each_with_index{|cell, i, j|
    self[i, j] = cell
  }
end

.widthObject

ワークシートの幅を返します



62
63
64
65
66
67
68
# File 'lib/metric_tools/spread_sheet.rb', line 62

def width
  max = 0
  @worksheet.cells.each do |coord, val|
    max = coord[1] if coord[1] >= max
  end
  max
end