knjrbfw 0.0.31 → 0.0.32

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.31
1
+ 0.0.32
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjrbfw}
8
- s.version = "0.0.31"
8
+ s.version = "0.0.32"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
@@ -260,6 +260,7 @@ Gem::Specification.new do |s|
260
260
  "spec/strings_spec.rb",
261
261
  "spec/threadsafe_spec.rb",
262
262
  "spec/web_spec.rb",
263
+ "spec/wref_spec.rb",
263
264
  "testfiles/image.jpg"
264
265
  ]
265
266
  s.homepage = %q{http://github.com/kaspernj/knjrbfw}
@@ -4,8 +4,10 @@ module Knj
4
4
  CONFIG = {}
5
5
 
6
6
  def self.const_missing(name)
7
- if name == "db"
8
- filepath = "#{$knjpath}/knjdb/libknjdb"
7
+ if name == :Db
8
+ filepath = "#{$knjpath}knjdb/libknjdb"
9
+ elsif name == :Wref_map
10
+ filepath = "#{$knjpath}wref"
9
11
  else
10
12
  filepath = "#{$knjpath}#{name.to_s.downcase}"
11
13
  end
@@ -36,6 +36,9 @@ class Knj::Process
36
36
  else
37
37
  $stderr.print "Process error: #{str}"
38
38
  end
39
+
40
+ #Try to break out of loop - the process has been destroyed.
41
+ break if (!@out_mutex and str.to_s.strip.length <= 0) or (@args and @args[:err] and @args[:err].closed?)
39
42
  end
40
43
  end
41
44
  end
@@ -67,10 +70,15 @@ class Knj::Process
67
70
  def listen
68
71
  loop do
69
72
  self.listen_loop
73
+
74
+ #Break out if something is wrong.
75
+ break if !@out_mutex or (@in and @in.closed?) or (@out and @out.closed?)
70
76
  end
71
77
  end
72
78
 
73
79
  def listen_loop
80
+ $stderr.print "listen-loop called.\n" if @debug
81
+
74
82
  str = @in.gets("\n")
75
83
  if str == nil
76
84
  raise "Socket closed." if @in.closed?
@@ -425,6 +433,7 @@ class Knj::Process
425
433
  self.kill_listen
426
434
  @err_thread.kill if @err_thread
427
435
  @out_answers = nil
436
+ @out_mutex = nil
428
437
  end
429
438
  end
430
439
 
@@ -383,6 +383,7 @@ class Knj::Process_meta
383
383
  raise e if e.message.index("No such process") == nil
384
384
  end
385
385
 
386
+ $stderr.print "Try to kill again...\n"
386
387
  retry
387
388
  end
388
389
 
@@ -14,6 +14,37 @@ class Knj::Table_writer
14
14
  @wb = Spreadsheet::Workbook.new
15
15
  @ws = @wb.create_worksheet
16
16
  @row = 0
17
+ elsif @args["format"] == "excel2007"
18
+ require "php_process"
19
+
20
+ @php = Php_process.new
21
+ @php.func("require_once", "PHPExcel.php")
22
+
23
+ if @args["date_format"]
24
+ @date_format_excel = args["date_format"].gsub("d", "dd").gsub("m", "mm").gsub("y", "yy").gsub("Y", "yyyy").gsub("-", '\\-')
25
+ end
26
+
27
+ #Array used for identifiyng Excel-columns.
28
+ @colarr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
29
+
30
+ #This greatly speeds up the process, since it minimizes the call to PHP by ~25%.
31
+ @date_cache = {}
32
+
33
+ #Set cache-mode to cache-in-memory-gzip.
34
+ cache_gzip_const = @php.constant_val("PHPExcel_CachedObjectStorageFactory::cache_to_discISAM")
35
+ cosf = @php.static("PHPExcel_CachedObjectStorageFactory", "initialize", cache_gzip_const)
36
+ @php.static("PHPExcel_Settings", "setCacheStorageMethod", cosf)
37
+
38
+ #Create PHPExcel-objects.
39
+ @pe = @php.new("PHPExcel")
40
+ @pe.getProperties.setCreator(args["creator"]) if args["creator"]
41
+ @pe.getProperties.setLastModifiedBy(args["last_modified_by"]) if args["last_modified_by"]
42
+ @pe.getProperties.setTitle(args["title"]) if args["title"]
43
+ @pe.getProperties.setSubject(args["subject"]) if args["subject"]
44
+ @pe.getProperties.setDescription(args["descr"]) if args["descr"]
45
+ @pe.setActiveSheetIndex(0)
46
+ @sheet = @pe.getActiveSheet
47
+ @linec = 1
17
48
  else
18
49
  raise "Unsupported format: '#{@args["format"]}'."
19
50
  end
@@ -33,8 +64,6 @@ class Knj::Table_writer
33
64
 
34
65
  line_str = Knj::Csv.arr_to_csv(arr, @args["expl"], @args["surr"])
35
66
 
36
- #line_str = line_str.encode("iso8859-1") if @args["encoding"] == "iso8859-1"
37
-
38
67
  @fp.write(line_str)
39
68
  elsif @args["format"] == "excel5"
40
69
  col_count = 0
@@ -51,6 +80,29 @@ class Knj::Table_writer
51
80
  end
52
81
 
53
82
  @row += 1
83
+ elsif @args["format"] == "excel2007"
84
+ col_count = 0
85
+ arr.each do |val|
86
+ colval = "#{@colarr[col_count]}#{@linec}"
87
+
88
+ if val.is_a?(Hash) and val["type"] == "decimal"
89
+ @sheet.setCellValue(colval, val["value"])
90
+ @sheet.getStyle(colval).getNumberFormat.setFormatCode("#,##0.00")
91
+ elsif val.is_a?(Hash) and val["type"] == "date"
92
+ datet = Knj::Datet.in(val["value"])
93
+ datet.days + 1
94
+
95
+ date_val = @php.static("PHPExcel_Shared_Date", "PHPToExcel", datet.to_i)
96
+ @sheet.setCellValue(colval, date_val)
97
+ @sheet.getStyle(colval).getNumberFormat.setFormatCode(@date_format_excel)
98
+ else
99
+ @sheet.setCellValue(colval, val)
100
+ end
101
+
102
+ col_count += 1
103
+ end
104
+
105
+ @linec += 1
54
106
  else
55
107
  raise "Unsupported format: '#{@args["format"]}'."
56
108
  end
@@ -58,6 +110,12 @@ class Knj::Table_writer
58
110
  return nil
59
111
  end
60
112
 
113
+ def destroy
114
+ @sheet = nil
115
+ @php.destroy if @php
116
+ @php = nil
117
+ end
118
+
61
119
  def close
62
120
  if @args["format"] == "csv"
63
121
  @fp.close
@@ -72,6 +130,10 @@ class Knj::Table_writer
72
130
  @ws = nil
73
131
 
74
132
  FileUtils.mv(temp_path, @args["filepath"])
133
+ elsif @args["format"] == "excel2007"
134
+ writer = @php.new("PHPExcel_Writer_Excel2007", @pe)
135
+ writer.save(@args["filepath"])
136
+ self.destroy
75
137
  else
76
138
  raise "Unsupported format: '#{@args["format"]}'."
77
139
  end
@@ -84,6 +146,8 @@ class Knj::Table_writer
84
146
  return "csv"
85
147
  elsif @args["format"] == "excel5"
86
148
  return "xls"
149
+ elsif @args["format"] == "excel2007"
150
+ return "xlsx"
87
151
  else
88
152
  raise "Unsupported format: '#{@args["format"]}'."
89
153
  end
@@ -92,7 +156,7 @@ class Knj::Table_writer
92
156
  def ftype
93
157
  if @args["format"] == "csv"
94
158
  return "text/csv"
95
- elsif @args["format"] == "excel5"
159
+ elsif @args["format"] == "excel5" or @args["format"] == "excel2007"
96
160
  return "application/ms-excel"
97
161
  else
98
162
  raise "Unsupported format: '#{@args["format"]}'."
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Wref" do
4
+ it "should load by using autoload" do
5
+ require "knjrbfw"
6
+
7
+ #Autoload wref-map.
8
+ Knj::Wref_map
9
+ end
10
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knjrbfw
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.31
5
+ version: 0.0.32
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -332,6 +332,7 @@ files:
332
332
  - spec/strings_spec.rb
333
333
  - spec/threadsafe_spec.rb
334
334
  - spec/web_spec.rb
335
+ - spec/wref_spec.rb
335
336
  - testfiles/image.jpg
336
337
  has_rdoc: true
337
338
  homepage: http://github.com/kaspernj/knjrbfw
@@ -347,7 +348,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
347
348
  requirements:
348
349
  - - ">="
349
350
  - !ruby/object:Gem::Version
350
- hash: -1220639088849160956
351
+ hash: -468641823555202698
351
352
  segments:
352
353
  - 0
353
354
  version: "0"