xlsx-DSL 0.0.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cd530608ea3bf494fc7f45f2d212c154187a8c1bb8480d41dac3bec9f35622b
4
- data.tar.gz: a4018d34d5491fdde3f193f3ad66d1357225e851ecec592b5d3aa3e0b9fc0784
3
+ metadata.gz: f62e46d625e1e271ad297beca2799c9a9dc7feb2087113ce5732f1c5d7bfa169
4
+ data.tar.gz: 0f008e537c785e6d4c3656eac25a21c15857dd86b7bf772317f5abf2b2082d31
5
5
  SHA512:
6
- metadata.gz: 03a727e570a0aa418c3de6a6c68f9a15edea3bc249aa4370c915a66a1977cfb099aba90fc5aaac945bad0e6d9982147ef92ee1a71638eda202de4472d472d94a
7
- data.tar.gz: 393be7432a03610653d4b8520f3cc5edd89c35daa44900930306c4dc81654a027358079670e12b77fbc3186c09f02069ccc168d21e0002379cea36df40f5179c
6
+ metadata.gz: 5f45435a4a9202904bae705e3bd69ab8e81743f5365557e3222d7296c65e55ff95d74c085de4d03f6e94909483b693aff245797b4aa34963357520101d558268
7
+ data.tar.gz: b550cfc657cbfdacb9669d20920ec74c52c72dcaa7fd64fb6f35642bae8dbac2aa066d3b5cc3b26d45bb3922ea59c5d14407103483539ab46ec8750b69049a63
@@ -1,7 +1,7 @@
1
1
  module OpenXML
2
2
  module SpreadsheetML
3
3
  module DSL
4
- VERSION = '0.0.0'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
  end
7
7
  end
data/lib/xlsx/DSL.rb CHANGED
@@ -1,4 +1,12 @@
1
- rbs_path = File.expand_path('DSL', File.dirname(__FILE__))
2
- for file in Dir.entries(rbs_path)
3
- require(File.expand_path($1, rbs_path)) if /(.*)\.rb$/.match(file)
4
- end
1
+ %w{
2
+ zip
3
+ nokogiri
4
+
5
+ xlsx/parser
6
+ xlsx/shared_string
7
+ xlsx/sheet
8
+ xlsx/sheet_data
9
+ xlsx/workbook
10
+
11
+ xlsx/DSL/version
12
+ }.each {|x| require x}
data/lib/xlsx/sheet.rb CHANGED
@@ -18,15 +18,25 @@ module OpenXML
18
18
  end
19
19
 
20
20
  def [] index
21
- self.merge_cells.each do |mc|
22
- if mc.include?(index)
23
- index = mc.top_left
24
- end
21
+ case index
22
+ when /^[A-Z]+\d+$/
23
+ retrieve_one_cell index
24
+ when /^\d+$/
25
+ retrieve_one_row index
26
+ when /^[A-Z]+$/
27
+ retrieve_one_column index
28
+ when /^(\d+)[\-:](\d+)$/
29
+ retrieve_rows($1, $2)
30
+ when /^([A-Z]+)[\-:]([A-Z]+)$/
31
+ retrieve_columns($1, $2)
32
+ else
33
+ raise IndexError, 'Invalid index'
25
34
  end
26
- self.sheet_data[index]
27
35
  end
28
36
 
29
- alias at_cell []
37
+ def at_cell index
38
+ retrieve_one_cell index
39
+ end
30
40
 
31
41
  def self.parser content
32
42
  doc = Nokogiri::XML content
@@ -57,6 +67,57 @@ module OpenXML
57
67
 
58
68
  Sheet.new(dimension, sheet_data, merge_cells)
59
69
  end
70
+
71
+ def max_column
72
+ /([A-Z]+)\d+$/.match(dimension)[1]
73
+ end
74
+
75
+ def max_row
76
+ /[A-Z]+(\d+)$/.match(dimension)[1]
77
+ end
78
+
79
+ private
80
+
81
+ def retrieve_one_cell index
82
+ self.merge_cells.each do |mc|
83
+ if mc.include?(index)
84
+ index = mc.top_left
85
+ end
86
+ end
87
+ self.sheet_data[index].value
88
+ end
89
+
90
+ def retrieve_one_row index
91
+ cells = []
92
+ ('A'..max_column).each do |col|
93
+ cells << retrieve_one_cell(col+index)
94
+ end
95
+ cells
96
+ end
97
+
98
+ def retrieve_rows(one, two)
99
+ cells = []
100
+ (one.to_i..two.to_i).each do |row_index|
101
+ cells << retrieve_one_row(row_index.to_s)
102
+ end
103
+ cells
104
+ end
105
+
106
+ def retrieve_one_column index
107
+ cells = []
108
+ (1..max_row.to_i).each do |row|
109
+ cells << retrieve_one_cell(index+row.to_s)
110
+ end
111
+ cells
112
+ end
113
+
114
+ def retrieve_columns(one, two)
115
+ cells = []
116
+ (one..two).each do |column_index|
117
+ cells << retrieve_one_column(column_index)
118
+ end
119
+ cells
120
+ end
60
121
  end
61
122
 
62
123
  class MergeCell
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlsx-DSL
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyan Yan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-11 00:00:00.000000000 Z
11
+ date: 2023-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -58,7 +58,6 @@ executables: []
58
58
  extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
- - lib/xlsx.rb
62
61
  - lib/xlsx/DSL.rb
63
62
  - lib/xlsx/DSL/version.rb
64
63
  - lib/xlsx/parser.rb
@@ -66,7 +65,7 @@ files:
66
65
  - lib/xlsx/sheet.rb
67
66
  - lib/xlsx/sheet_data.rb
68
67
  - lib/xlsx/workbook.rb
69
- homepage: https://rubygems.org/gems/xlsx-DSL
68
+ homepage: https://github.com/coalooball/xlsx-DSL
70
69
  licenses:
71
70
  - MIT
72
71
  metadata: {}
data/lib/xlsx.rb DELETED
@@ -1,7 +0,0 @@
1
- rbs_path = File.expand_path('xlsx', File.dirname(__FILE__))
2
- for file in Dir.entries(rbs_path)
3
- require(File.expand_path($1, rbs_path)) if /(.*)\.rb$/.match(file)
4
- end
5
-
6
- require "zip"
7
- require "nokogiri"