spreadshoot 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/spreadshoot/version.rb +1 -1
- data/lib/spreadshoot.rb +34 -3
- metadata +49 -30
data/lib/spreadshoot/version.rb
CHANGED
data/lib/spreadshoot.rb
CHANGED
@@ -62,6 +62,8 @@ class Spreadshoot
|
|
62
62
|
14
|
63
63
|
when :percent
|
64
64
|
10
|
65
|
+
when :currency
|
66
|
+
7
|
65
67
|
else
|
66
68
|
value
|
67
69
|
end
|
@@ -336,6 +338,7 @@ class Spreadshoot
|
|
336
338
|
attr_reader :title, :xml, :spreadsheet, :row_index, :col_index, :cells
|
337
339
|
|
338
340
|
# Not intended to be called directly. Use Spreadshoot#worksheet to create a worksheet.
|
341
|
+
# @private
|
339
342
|
def initialize spreadsheet, title, options = {}
|
340
343
|
@cells = {}
|
341
344
|
@spreadsheet = spreadsheet
|
@@ -351,6 +354,7 @@ class Spreadshoot
|
|
351
354
|
end
|
352
355
|
|
353
356
|
# Outputs the worksheet as OOXML
|
357
|
+
# @private
|
354
358
|
def to_s
|
355
359
|
@xml ||= Builder::XmlMarkup.new.worksheet(:xmlns => "http://schemas.openxmlformats.org/spreadsheetml/2006/main") do |ws|
|
356
360
|
unless @column_widths.empty?
|
@@ -379,6 +383,7 @@ class Spreadshoot
|
|
379
383
|
|
380
384
|
# Creates a row within a worksheet.
|
381
385
|
#
|
386
|
+
# @see Table#row
|
382
387
|
# @param [Hash] options options to create a row with.
|
383
388
|
# @return created row
|
384
389
|
def row options = {}, &block
|
@@ -405,6 +410,7 @@ class Spreadshoot
|
|
405
410
|
end
|
406
411
|
|
407
412
|
# Not intended to be used directly.
|
413
|
+
# @private
|
408
414
|
def set_col_width col, width
|
409
415
|
@column_widths[col] = width
|
410
416
|
end
|
@@ -416,6 +422,8 @@ class Spreadshoot
|
|
416
422
|
class Table
|
417
423
|
attr_reader :worksheet, :direction, :col_max, :row_max, :col_index, :row_index, :row_topleft, :col_topleft
|
418
424
|
|
425
|
+
# @private
|
426
|
+
# @see Worksheet#table
|
419
427
|
def initialize worksheet, options = {}
|
420
428
|
@worksheet = worksheet
|
421
429
|
@options = options
|
@@ -474,11 +482,22 @@ class Spreadshoot
|
|
474
482
|
|
475
483
|
# A row of a table. The table could be horizontal oriented, or vertical oriented.
|
476
484
|
class Row
|
485
|
+
# @private
|
486
|
+
# @note Do not call directly, rows should be created using Table#row or #Worksheet#row methods
|
487
|
+
#
|
488
|
+
# @see Table#row
|
489
|
+
# @see Worksheet#row
|
477
490
|
def initialize table, options = {}
|
478
491
|
@table = table
|
479
492
|
@options = options
|
480
493
|
end
|
481
494
|
|
495
|
+
# Creates a cell within a row.
|
496
|
+
#
|
497
|
+
# @param [Object] value a value to write to the cell
|
498
|
+
# @param [Hash] options additional options applied (formatting, etc)
|
499
|
+
#
|
500
|
+
# @return created Cell instance
|
482
501
|
def cell value = nil, options = {}
|
483
502
|
cell = Cell.new(@table, value, @options.merge(options))
|
484
503
|
@table.worksheet.cells[@table.current_row] ||= {}
|
@@ -494,13 +513,17 @@ class Spreadshoot
|
|
494
513
|
|
495
514
|
# A cell within a row.
|
496
515
|
class Cell
|
516
|
+
@alpha_indices ||= ('A'..'ZZ').to_a
|
497
517
|
# maps numeric column indices to letter based:
|
498
518
|
# 0 -> 'A', 1 -> 'B', 26 -> 'AA' and so on
|
519
|
+
# @return [String]
|
499
520
|
def self.alpha_index i
|
500
|
-
@alpha_indices ||= ('A'..'ZZ').to_a
|
501
521
|
@alpha_indices[i]
|
502
522
|
end
|
503
523
|
|
524
|
+
# @note Do not use directly, use Row#cell to create a cell.
|
525
|
+
# @private
|
526
|
+
# @see Row#cell
|
504
527
|
def initialize table, value, options = {}
|
505
528
|
@table = table
|
506
529
|
@value = value
|
@@ -510,17 +533,23 @@ class Spreadshoot
|
|
510
533
|
@options[:format] ||= :date if @value.is_a?(Date) || @value.is_a?(Time)
|
511
534
|
end
|
512
535
|
|
536
|
+
# Zero-based index of the current column of the cell
|
537
|
+
# @return [Fixnum]
|
513
538
|
def current_col
|
514
539
|
@table.current_col
|
515
540
|
end
|
516
541
|
|
542
|
+
# Zero-based index of the current row of the cell
|
543
|
+
# @return [Fixnum]
|
517
544
|
def current_row
|
518
545
|
@table.current_row
|
519
546
|
end
|
520
547
|
|
521
|
-
#
|
548
|
+
# Outputs the cell into the resulting xml
|
549
|
+
# @private
|
522
550
|
def output xn_parent
|
523
551
|
r = {:r => @coords}
|
552
|
+
@options = @value if @value.is_a?(Hash)
|
524
553
|
if style = @table.worksheet.spreadsheet.style(@options)
|
525
554
|
r.merge!(:s => style + 1)
|
526
555
|
end
|
@@ -529,7 +558,6 @@ class Spreadshoot
|
|
529
558
|
i = @table.worksheet.spreadsheet.ss_index(@value)
|
530
559
|
xn_parent.c(r.merge(:t => 's')){ |xc| xc.v(i) }
|
531
560
|
when Hash # no @value, formula in options
|
532
|
-
@options = @value
|
533
561
|
xn_parent.c(r) do |xc|
|
534
562
|
xc.f(@options[:formula])
|
535
563
|
end
|
@@ -544,6 +572,9 @@ class Spreadshoot
|
|
544
572
|
end
|
545
573
|
end
|
546
574
|
|
575
|
+
# Outputs cell coordinates (e.g. "C3", "AG41" and so on)
|
576
|
+
#
|
577
|
+
# @return [String]
|
547
578
|
def to_s
|
548
579
|
@coords
|
549
580
|
end
|
metadata
CHANGED
@@ -1,34 +1,45 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: spreadshoot
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Mladen Jablanovic
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2013-01-25 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: builder
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
22
31
|
type: :runtime
|
23
|
-
|
24
|
-
version_requirements: *80585380
|
32
|
+
version_requirements: *id001
|
25
33
|
description: Create XLSX files from scratch using Ruby
|
26
|
-
email:
|
34
|
+
email:
|
27
35
|
- jablan@radioni.ca
|
28
36
|
executables: []
|
37
|
+
|
29
38
|
extensions: []
|
39
|
+
|
30
40
|
extra_rdoc_files: []
|
31
|
-
|
41
|
+
|
42
|
+
files:
|
32
43
|
- .gitignore
|
33
44
|
- Gemfile
|
34
45
|
- LICENSE
|
@@ -38,29 +49,37 @@ files:
|
|
38
49
|
- lib/spreadshoot.rb
|
39
50
|
- lib/spreadshoot/version.rb
|
40
51
|
- spreadshoot.gemspec
|
52
|
+
has_rdoc: true
|
41
53
|
homepage: https://github.com/jablan/spreadshoot
|
42
54
|
licenses: []
|
55
|
+
|
43
56
|
post_install_message:
|
44
57
|
rdoc_options: []
|
45
|
-
|
58
|
+
|
59
|
+
require_paths:
|
46
60
|
- lib
|
47
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
62
|
none: false
|
49
|
-
requirements:
|
50
|
-
- -
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
|
53
|
-
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
70
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
59
77
|
requirements: []
|
78
|
+
|
60
79
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.
|
80
|
+
rubygems_version: 1.3.7
|
62
81
|
signing_key:
|
63
82
|
specification_version: 3
|
64
83
|
summary: Ruby DSL for creating Excel xlsx spreadsheets
|
65
84
|
test_files: []
|
66
|
-
|
85
|
+
|