zaphire 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/zaphire.rb +225 -0
  3. data/test/test_zaphire.rb +10 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e49d1f9039ea5aa6ebb13a4f62fb1ce77bf33be5
4
+ data.tar.gz: 137b249110869e5a3e209ee43bf1e954ea0fc5fc
5
+ SHA512:
6
+ metadata.gz: 23e6f16c246d180b2572fdc9261190b1d592fac6b1b653ca9bf1bac62fda5571a6c39f7fc185cacc3af1460f1bdfe49114f5cf31938cb017e65c99b8a6f85911
7
+ data.tar.gz: 0c60b2b1722b916bbe5ffbeea643f9dab71cd9ecc1f9ffc52c0959f36d54a9db4bfc70f84230852a53ee33c565d49f809570b35bb51471013adf18ee5edc19ba
data/lib/zaphire.rb ADDED
@@ -0,0 +1,225 @@
1
+ require 'roo'
2
+ #require 'google-spreadsheet-ruby'
3
+ require 'matrix'
4
+ require 'google_drive'
5
+ require 'csv'
6
+ require 'open-uri'
7
+
8
+ module Zsave
9
+
10
+ def self.csv(arr,file,mode="w",opts={})
11
+
12
+ arr = arr.to_a
13
+
14
+ File.open(file,mode){ |f| f << arr.map(&:to_csv).join("\n") }
15
+
16
+ #open(path,mode,opts){ |csv| array.each{ |row| csv << row } }
17
+ end
18
+
19
+ def self.cvs(array,path,mode="w",opts={})
20
+
21
+ arr = arr.to_a
22
+
23
+ File.open(file,mode){ |f| f << arr.map(&:to_csv).join("\n") }
24
+
25
+ #open(path,mode,opts){ |csv| array.each{ |row| csv << row } }
26
+ end
27
+
28
+ end
29
+
30
+
31
+ module Zgdocs
32
+
33
+ def self.save key,sheet,startcel,data,user,password
34
+
35
+ t = Roo::Google.new(key, user: user, password: password)
36
+ t.default_sheet = sheet
37
+
38
+ rowstart = startcel[0]
39
+ colstart = startcel[1]
40
+
41
+ curRow = rowstart
42
+
43
+ rowstosave = data.row_size
44
+ sheetrows = Zgdocs.makesurethereisrows(rowstosave,key,sheet,user,password)
45
+
46
+ puts "Data to save: " << data.to_s
47
+ puts "Rows : " << rowstosave.to_s
48
+
49
+ xx = data.row_size - 1
50
+
51
+ 0.upto(xx) do |therow|
52
+
53
+ curCol = colstart
54
+
55
+ m "ZgdocsSaving Row",therow,xx
56
+
57
+ data.row(therow).each do |value|
58
+
59
+ #0.upto(row.column_count) do |col|
60
+
61
+ # puts "ZgdocsSaving row: " << curRow.to_s << " col: " << curCol.to_s << " Value: " << value.to_s
62
+
63
+ # value = data[rownum,colnum]
64
+
65
+ t.set(curRow, curCol, value, sheet)
66
+
67
+ curCol += 1
68
+ end
69
+
70
+ curRow += 1
71
+
72
+ end
73
+ end
74
+
75
+ def self.makesurethereisrows rows,key,sheet,user,password
76
+ t = Roo::Google.new(key, user: user, password: password)
77
+
78
+ session = GoogleDrive.login(user, password)
79
+
80
+ ws = session.spreadsheet_by_key(key).worksheet_by_title(sheet)
81
+
82
+ ws.max_rows = (rows + 2) if ws.max_rows < rows
83
+
84
+ end
85
+
86
+ def self.makesurethereissheet sheet,key,user,password
87
+ t = Roo::Google.new(key, user: user, password: password)
88
+
89
+ unless t.sheets.include?(sheet)
90
+ session = GoogleDrive.login(user, password)
91
+ ws = session.spreadsheet_by_key(key)
92
+ worksheet = ws.add_worksheet(sheet)
93
+ end
94
+ end
95
+ end
96
+
97
+ def it
98
+ @it
99
+ end
100
+
101
+ def get a
102
+ @it = a
103
+ end
104
+
105
+ def trunc a, decimals = 0
106
+ if decimals == 0
107
+ a.to_i
108
+ else
109
+ b = '%.' << decimals << "f"
110
+ sprintf(b,a)
111
+ end
112
+ end
113
+
114
+ def put a
115
+ puts a.to_s
116
+ end
117
+
118
+ def d a
119
+ puts a
120
+ end
121
+
122
+ def m itext,i,xx,iadditional = ""
123
+ tt = xx.to_f + 1.00
124
+ aa = trunc( (( (i.to_f+1) / tt) * 100) )
125
+ it = itext << ": (" << aa.to_s << "%)"
126
+
127
+ return "" if @mvar == it
128
+ @mvar = it
129
+
130
+ texttodisp = @mvar << " " << iadditional
131
+
132
+ i += 1
133
+ xx += 1
134
+
135
+ @mstart = theticks() if i == 1
136
+ return "" if i == 1 or xx == 1
137
+
138
+ it = trunc( (i.to_f / tt*10) )
139
+
140
+ ee = ( (theticks.to_f - @mstart.to_f) / 60) * ( (tt - i)/i.to_f )
141
+ aa = trunc( ee )
142
+ bb = trunc( aa.to_f / 60 )
143
+ cc1 = aa.to_f / 60
144
+ cc2 = trunc( (aa.to_f / 60) )
145
+ cc = trunc( (cc1 - cc2 ) * 60 )
146
+
147
+ cc = "0" << cc.to_s if cc.to_s.size == 1
148
+
149
+ it = "[" << " XXXXXXXXXX"[1..it.to_i] << " __________"[1..(10-it.to_i)] << "] " << texttodisp << " (" << bb.to_s << ":" << cc.to_s << " Min. left) " << i.to_i.to_s << " of " << tt.to_i.to_s
150
+
151
+ d it
152
+
153
+ iSetMsgForTerm(@itermattended, it) unless @itermattended
154
+ end
155
+
156
+ def iSetMsgForTerm iterm,imessage
157
+
158
+ end
159
+
160
+ # on m itext,i,xx
161
+ # global mvar,mtim,mstart,iTermAttended
162
+ # put trunc(i/xx*100) into aa
163
+ # get itext&": ("&aa&"%)"
164
+ # if mvar is it then exit m else put it into mvar
165
+ # if i is 1 then put the ticks into mstart
166
+ # if i is 0 or xx is 0 then exit m
167
+ # get trunc(i/xx*10)
168
+ # put trunc((the ticks-mstart)/(60)* ((xx-i)/i)) into aa
169
+ # put trunc(aa/60) into bb
170
+ # put trunc( (aa/60-trunc(aa/60))*60 ) into cc
171
+ # if length(cc) is 1 then put "0" before cc
172
+ # get "["&char 1 to it of " XXXXXXXXXX" & char 1 to (10-it) of "__________"&"]"&&mvar &&"("& bb&":"&cc&" Min. left)" &&i&&"of"&&xx
173
+ # d it
174
+ # if iTermAttended is not empty then get iSetMsgForTerm(iTermAttended,unquote(it))
175
+ # end m
176
+
177
+ def theticks
178
+ Time.now().to_i
179
+ end
180
+
181
+
182
+ class Matrix
183
+ def dump(firstLine = "")
184
+ str = ""
185
+ if firstLine != ""
186
+ str << firstLine << "\n"
187
+ end
188
+ for i in 0...self.row_size
189
+ space = ""
190
+ for j in 0...self.column_size
191
+ str << space << self[i,j].to_s
192
+ space = " "
193
+ end
194
+ str << "\n"
195
+ end
196
+ return str
197
+ end
198
+ # La classe Matrix est immutable, or je veux pouvoir écrire :
199
+ # m[i,j] = v
200
+ #
201
+ def []=(i, j, v)
202
+ @rows[i][j] = v
203
+ end
204
+ # Il n'y a même pas de constructeur pour une matrice rectangulaire : bouhhh
205
+ # Le prefixe "self." permet de déclarer une méthode de classe
206
+ def self.create(nbRows, nbCols, value)
207
+ return Matrix.rows(Array.new(nbRows, Array.new(nbCols,value)))
208
+ end
209
+ end
210
+
211
+
212
+ def left a,b
213
+ c = b-1
214
+ a.to_s[0..c]
215
+ end
216
+
217
+ def chars a,b,c
218
+ c.to_s[a-1..b-1]
219
+ end
220
+
221
+ # visiblematrix.each_with_index do |x, xi|
222
+ # x.each_with_index do |y, yi|
223
+ # puts "element [#{xi}, #{yi}] is #{y}"
224
+ # end
225
+ # end
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require 'zaphire'
3
+
4
+ class ZaphireTest < Test::Unit::TestCase
5
+
6
+
7
+ def test_put
8
+ put "Just Like Hypercard! :) "
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zaphire
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lima90001
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A library to make Ruby nicer to HyperCard users and Myself
14
+ email: lima90001@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/zaphire.rb
20
+ - test/test_zaphire.rb
21
+ homepage: http://rubygems.org/gems/zaphire
22
+ licenses:
23
+ - AFL
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: Zaphire!
45
+ test_files:
46
+ - test/test_zaphire.rb