calexcer 0.0.5 → 0.0.6
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 +4 -4
- data/lib/calexcer/hashable.rb +23 -0
- data/lib/calexcer/loopable.rb +7 -7
- data/lib/calexcer/sheet.rb +24 -2
- data/lib/calexcer/sheet/horizontal_sheet.rb +4 -4
- data/lib/calexcer/sheet/vertical_sheet.rb +7 -5
- data/lib/calexcer/version.rb +1 -1
- data/spec/lib/calexcer/book_spec.rb +2 -2
- data/spec/lib/calexcer/cell_spec.rb +1 -0
- data/spec/lib/calexcer/{sheetable_spec.rb → hashable_spec.rb} +1 -1
- data/spec/lib/calexcer/sheet/horizontal_sheet_spec.rb +4 -0
- data/spec/lib/calexcer/sheet/vertical_sheet_spec.rb +4 -0
- data/spec/lib/calexcer/sheet_spec.rb +2 -2
- data/spec/lib/shared_spec/shared_hashable_spec.rb +30 -0
- data/spec/sample/horizontal_calendar.xls +0 -0
- data/spec/sample/vertical_calendar.xls +0 -0
- data/spec/sample/vertical_calendar_merged_cell.xls +0 -0
- metadata +7 -5
- data/lib/calexcer/sheetable.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f98e54bd83b46de7d07efb4004d76cc8578425fa
|
4
|
+
data.tar.gz: bf1fc14995328e751b844715f9ebfecba62bdbc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 320703c057ab99929141cc9b1401b29b64967b50dfb39868b8e8313f76da4e6cfe4e9d25c5650ee87039f749c254676fe07e96ee816217fc5c9eac4f27eaaac9
|
7
|
+
data.tar.gz: 04899cefe67d440efb5e12c9fa01ca37c0b288fcfa5e063f38b8e2e19fd360ae94fe14097c8128725f0c59f94189e7d8b27a8f18e6dc7f00cdff11c25affc44a
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Calexcer
|
2
|
+
module Hashable
|
3
|
+
def to_hash(*args)
|
4
|
+
raise Calexcer::MethodNotImplementedError
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_reversed_hash(*args)
|
8
|
+
_events = {}
|
9
|
+
self.to_hash(*args).each do |date, events|
|
10
|
+
events.each do |event|
|
11
|
+
unless event.nil?
|
12
|
+
_events[event] ||= []
|
13
|
+
_events[event] << date
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
_events
|
19
|
+
end
|
20
|
+
alias_method :to_r_hash, :to_reversed_hash
|
21
|
+
alias_method :to_hashr, :to_reversed_hash
|
22
|
+
end
|
23
|
+
end
|
data/lib/calexcer/loopable.rb
CHANGED
@@ -40,12 +40,12 @@ module Calexcer
|
|
40
40
|
cell
|
41
41
|
end
|
42
42
|
|
43
|
-
def loop(&block)
|
43
|
+
def loop(*args, &block)
|
44
44
|
raise Calexcer::MethodNotImplementedError
|
45
45
|
end
|
46
46
|
|
47
|
-
def loop_vertical(&block)
|
48
|
-
loop_will_start
|
47
|
+
def loop_vertical(*args, &block)
|
48
|
+
loop_will_start(*args)
|
49
49
|
(self.col_start..self.col_end).each do |col|
|
50
50
|
horizontal_loop_unit_will_start(col)
|
51
51
|
(self.row_start..self.row_end).each do |row|
|
@@ -60,8 +60,8 @@ module Calexcer
|
|
60
60
|
loop_did_end
|
61
61
|
end
|
62
62
|
|
63
|
-
def loop_horizontal(&block)
|
64
|
-
loop_will_start
|
63
|
+
def loop_horizontal(*args, &block)
|
64
|
+
loop_will_start(*args)
|
65
65
|
(self.row_start..self.row_end).each do |row|
|
66
66
|
vertical_loop_unit_will_start(row)
|
67
67
|
(self.col_start..self.col_end).each do |col|
|
@@ -76,8 +76,8 @@ module Calexcer
|
|
76
76
|
loop_did_end
|
77
77
|
end
|
78
78
|
|
79
|
-
def loop_will_start
|
80
|
-
dimensions
|
79
|
+
def loop_will_start(*args)
|
80
|
+
dimensions(*args)
|
81
81
|
end
|
82
82
|
|
83
83
|
def loop_did_end
|
data/lib/calexcer/sheet.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
require "calexcer/
|
1
|
+
require "calexcer/hashable"
|
2
2
|
require "calexcer/cell"
|
3
3
|
|
4
4
|
module Calexcer
|
5
5
|
class Sheet
|
6
|
-
include Calexcer::
|
6
|
+
include Calexcer::Hashable
|
7
|
+
|
8
|
+
attr_reader :sheet
|
7
9
|
|
8
10
|
def self.sheet_class_name(name)
|
9
11
|
_name = []
|
@@ -22,9 +24,29 @@ module Calexcer
|
|
22
24
|
cell_class.new(self.sheet[row, col])
|
23
25
|
end
|
24
26
|
|
27
|
+
def [](row, col)
|
28
|
+
self.sheet[row, col]
|
29
|
+
end
|
30
|
+
|
31
|
+
#--------------------#
|
32
|
+
protected
|
33
|
+
|
34
|
+
attr_writer :sheet
|
35
|
+
|
25
36
|
#--------------------#
|
26
37
|
private
|
27
38
|
|
39
|
+
def dimensions(*args)
|
40
|
+
arg = args.shift||{}
|
41
|
+
|
42
|
+
@row_start, @row_end, @col_start, @col_end = self.sheet.dimensions
|
43
|
+
|
44
|
+
@row_start = arg[:row_start] || @row_start
|
45
|
+
@row_end = arg[:row_end] || @row_end
|
46
|
+
@col_start = arg[:col_start] || @col_start
|
47
|
+
@col_end = arg[:col_end] || @col_end
|
48
|
+
end
|
49
|
+
|
28
50
|
def sheet_class(name)
|
29
51
|
self.class.sheet_class_name(name)
|
30
52
|
end
|
@@ -12,11 +12,11 @@ module Calexcer
|
|
12
12
|
self.initialize_year_month(year: year, month: month)
|
13
13
|
end
|
14
14
|
|
15
|
-
def to_hash(
|
15
|
+
def to_hash(*args)
|
16
16
|
self.events = {}
|
17
17
|
self.dates = {}
|
18
18
|
|
19
|
-
self.loop do |cell|
|
19
|
+
self.loop(*args) do |cell|
|
20
20
|
case cell.value
|
21
21
|
when Date
|
22
22
|
self.cell_as_date(cell.value)
|
@@ -52,8 +52,8 @@ module Calexcer
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def loop(&block)
|
56
|
-
self.loop_horizontal(&block)
|
55
|
+
def loop(*args, &block)
|
56
|
+
self.loop_horizontal(*args, &block)
|
57
57
|
end
|
58
58
|
|
59
59
|
def horizontal_loop_unit_will_start(col)
|
@@ -10,11 +10,13 @@ module Calexcer
|
|
10
10
|
self.initialize_year_month(year: year, month: month)
|
11
11
|
end
|
12
12
|
|
13
|
-
def to_hash(
|
14
|
-
|
13
|
+
def to_hash(*args)
|
14
|
+
hash_args = args.shift||{}
|
15
|
+
|
16
|
+
self.ignore_header = hash_args[:ignore_header]||true
|
15
17
|
self.events = {}
|
16
18
|
|
17
|
-
self.loop do |cell|
|
19
|
+
self.loop(hash_args) do |cell|
|
18
20
|
if (self.ignore_header) && (! cell.value.nil?)
|
19
21
|
self.ignore_header = false
|
20
22
|
else
|
@@ -52,8 +54,8 @@ module Calexcer
|
|
52
54
|
self.add_event(self.current_date, string)
|
53
55
|
end
|
54
56
|
|
55
|
-
def loop(&block)
|
56
|
-
self.loop_vertical(&block)
|
57
|
+
def loop(*args, &block)
|
58
|
+
self.loop_vertical(*args, &block)
|
57
59
|
end
|
58
60
|
|
59
61
|
def vertical_loop_unit_will_start(row)
|
data/lib/calexcer/version.rb
CHANGED
@@ -23,9 +23,9 @@ describe Calexcer::Book do
|
|
23
23
|
expect(calexcer.sheets).to be_a(Array)
|
24
24
|
end
|
25
25
|
|
26
|
-
example "includes Calexcer::
|
26
|
+
example "includes Calexcer::Sheet" do
|
27
27
|
calexcer.sheets.each do |sheet|
|
28
|
-
expect(sheet).to be_a(Calexcer::
|
28
|
+
expect(sheet).to be_a(Calexcer::Sheet)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "lib/shared_spec/shared_hashable_spec"
|
2
3
|
|
3
4
|
describe Calexcer::HorizontalSheet do
|
4
5
|
let(:sample) { Calexcer::Samples[:horizontal] }
|
@@ -20,6 +21,9 @@ describe Calexcer::HorizontalSheet do
|
|
20
21
|
expect(events[Date.new(2014, 8, 3)]).to be_include("sunday game")
|
21
22
|
expect(events[Date.new(2014, 8, 31)]).to be_include("live")
|
22
23
|
end
|
24
|
+
|
25
|
+
it_behaves_like "specified dimensions"
|
26
|
+
|
23
27
|
end
|
24
28
|
|
25
29
|
describe "#to_reversed_hash" do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "lib/shared_spec/shared_hashable_spec"
|
2
3
|
|
3
4
|
describe Calexcer::VerticalSheet do
|
4
5
|
let(:sample) { Calexcer::Samples[:vertical] }
|
@@ -25,6 +26,9 @@ describe Calexcer::VerticalSheet do
|
|
25
26
|
example "block to get non-events" do
|
26
27
|
expect(sheet.to_hash.collect{|k,v| v}.flatten).not_to be_include("Description of the calendar")
|
27
28
|
end
|
29
|
+
|
30
|
+
it_behaves_like "specified dimensions"
|
31
|
+
|
28
32
|
end # describe "#to_hash"
|
29
33
|
|
30
34
|
describe "#to_reversed_hash" do
|
@@ -5,8 +5,8 @@ describe Calexcer::Sheet do
|
|
5
5
|
let(:calexcer) { Calexcer::Book.new(sample) }
|
6
6
|
let(:sheet) { calexcer.sheets.first }
|
7
7
|
|
8
|
-
example "
|
9
|
-
expect(sheet).to be_a(Calexcer::
|
8
|
+
example "Hashable" do
|
9
|
+
expect(sheet).to be_a(Calexcer::Hashable)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe ".sheet_class_name" do
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "specified dimensions" do
|
4
|
+
let(:specified_dimension) { 50 }
|
5
|
+
|
6
|
+
example "specified row start" do
|
7
|
+
expect do
|
8
|
+
sheet.to_hash(row_start: specified_dimension)
|
9
|
+
end.to change{ sheet.__send__(:row_start) }.from(nil).to(specified_dimension)
|
10
|
+
end
|
11
|
+
|
12
|
+
example "specified row end" do
|
13
|
+
expect do
|
14
|
+
sheet.to_hash(row_end: specified_dimension)
|
15
|
+
end.to change{ sheet.__send__(:row_end) }.from(nil).to(specified_dimension)
|
16
|
+
end
|
17
|
+
|
18
|
+
example "specified col start" do
|
19
|
+
expect do
|
20
|
+
sheet.to_hash(col_start: specified_dimension)
|
21
|
+
end.to change{ sheet.__send__(:col_start) }.from(nil).to(specified_dimension)
|
22
|
+
end
|
23
|
+
|
24
|
+
example "specified col end" do
|
25
|
+
expect do
|
26
|
+
sheet.to_hash(col_end: specified_dimension)
|
27
|
+
end.to change{ sheet.__send__(:col_end) }.from(nil).to(specified_dimension)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calexcer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sekizo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spreadsheet
|
@@ -134,21 +134,22 @@ files:
|
|
134
134
|
- lib/calexcer/book.rb
|
135
135
|
- lib/calexcer/cell.rb
|
136
136
|
- lib/calexcer/errors/method_not_implemented_error.rb
|
137
|
+
- lib/calexcer/hashable.rb
|
137
138
|
- lib/calexcer/loopable.rb
|
138
139
|
- lib/calexcer/sheet.rb
|
139
140
|
- lib/calexcer/sheet/horizontal_sheet.rb
|
140
141
|
- lib/calexcer/sheet/vertical_sheet.rb
|
141
|
-
- lib/calexcer/sheetable.rb
|
142
142
|
- lib/calexcer/version.rb
|
143
143
|
- spec/lib/calexcer/book_spec.rb
|
144
144
|
- spec/lib/calexcer/cell_spec.rb
|
145
|
+
- spec/lib/calexcer/hashable_spec.rb
|
145
146
|
- spec/lib/calexcer/loopable_spec.rb
|
146
147
|
- spec/lib/calexcer/sheet/horizontal_sheet_spec.rb
|
147
148
|
- spec/lib/calexcer/sheet/vertical_sheet_merged_cell_spec.rb
|
148
149
|
- spec/lib/calexcer/sheet/vertical_sheet_spec.rb
|
149
150
|
- spec/lib/calexcer/sheet_spec.rb
|
150
|
-
- spec/lib/calexcer/sheetable_spec.rb
|
151
151
|
- spec/lib/calexcer_spec.rb
|
152
|
+
- spec/lib/shared_spec/shared_hashable_spec.rb
|
152
153
|
- spec/sample/horizontal_calendar.xls
|
153
154
|
- spec/sample/vertical_calendar.xls
|
154
155
|
- spec/sample/vertical_calendar_merged_cell.xls
|
@@ -180,13 +181,14 @@ summary: Convert excel sheet to object as calendar.
|
|
180
181
|
test_files:
|
181
182
|
- spec/lib/calexcer/book_spec.rb
|
182
183
|
- spec/lib/calexcer/cell_spec.rb
|
184
|
+
- spec/lib/calexcer/hashable_spec.rb
|
183
185
|
- spec/lib/calexcer/loopable_spec.rb
|
184
186
|
- spec/lib/calexcer/sheet/horizontal_sheet_spec.rb
|
185
187
|
- spec/lib/calexcer/sheet/vertical_sheet_merged_cell_spec.rb
|
186
188
|
- spec/lib/calexcer/sheet/vertical_sheet_spec.rb
|
187
189
|
- spec/lib/calexcer/sheet_spec.rb
|
188
|
-
- spec/lib/calexcer/sheetable_spec.rb
|
189
190
|
- spec/lib/calexcer_spec.rb
|
191
|
+
- spec/lib/shared_spec/shared_hashable_spec.rb
|
190
192
|
- spec/sample/horizontal_calendar.xls
|
191
193
|
- spec/sample/vertical_calendar.xls
|
192
194
|
- spec/sample/vertical_calendar_merged_cell.xls
|
data/lib/calexcer/sheetable.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module Calexcer
|
2
|
-
module Sheetable
|
3
|
-
attr_reader :sheet
|
4
|
-
|
5
|
-
def to_hash(ignore_header: true)
|
6
|
-
raise Calexcer::MethodNotImplementedError
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_reversed_hash(ignore_header: true)
|
10
|
-
_events = {}
|
11
|
-
self.to_hash(ignore_header: ignore_header).each do |date, events|
|
12
|
-
events.each do |event|
|
13
|
-
unless event.nil?
|
14
|
-
_events[event] ||= []
|
15
|
-
_events[event] << date
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
_events
|
21
|
-
end
|
22
|
-
alias_method :to_r_hash, :to_reversed_hash
|
23
|
-
alias_method :to_hashr, :to_reversed_hash
|
24
|
-
|
25
|
-
#--------------------#
|
26
|
-
protected
|
27
|
-
|
28
|
-
attr_writer :sheet
|
29
|
-
|
30
|
-
#--------------------#
|
31
|
-
private
|
32
|
-
|
33
|
-
def dimensions
|
34
|
-
@row_start, @row_end, @col_start, @col_end = self.sheet.dimensions
|
35
|
-
end
|
36
|
-
|
37
|
-
def method_missing(name, *args, &block)
|
38
|
-
begin
|
39
|
-
self.sheet.__send__(name, *args, &block)
|
40
|
-
rescue => e
|
41
|
-
super
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|