calexcer 0.0.5

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4df6ed64af2eb680363c5ed41f469665f6c5cc2b
4
+ data.tar.gz: e73d24868c0a7f6ea9831bbb4e99b4d60559d9e7
5
+ SHA512:
6
+ metadata.gz: 2d78a4dd9ba69a04ab71534f4258d9aefe7189aee4d542a385e1179a7b35366eded8dff788beb61aba24d028bf17fc4bfa9ecbc190717425d3bd29edcbd3f858
7
+ data.tar.gz: 78742f2bd713c52e415ebc18aef0e093d02cd9543eb1a7516f4885d05f40a7c4af4dd99ec10dc747a9236b78c724b18f7970328cbd5ee07d8c01fe027a2c916b
data/.gitignore ADDED
@@ -0,0 +1,30 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ ._DS_Store
24
+ log/
25
+ private
26
+ .project
27
+ bundle/
28
+ private.*
29
+ .DS_Store
30
+ ._*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in calexcer.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cmd: "bundle exec rspec" do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 sekizo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Calexcer
2
+
3
+ Convert excel sheet to object as calendar.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'calexcer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install calexcer
18
+
19
+ ## Usage
20
+
21
+ require "calexcer"
22
+ book = Calexcer::Book.new("PATH/TO/excel.xls") # => Calexcer::Book
23
+ sheet = book.sheets[0] # => Calexcer::Sheet
24
+ v_sheet = sheet.vertical_sheet # => Calexcer::VerticalSheet
25
+
26
+ v_sheet.to_hash
27
+ # => { date_1 => ["one day event", "repeat event 1"], date_2 => ["repeat event 1", "repeat event 2"], date_3 => ["repeat event 2"] }
28
+
29
+ v_sheet.to_hashr
30
+ # => { "one day event" => [date_1], "repeat event 1" => [date_1, date_2], "repeat event 2" => [date_2, date_3] }
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/sekizo/calexcer/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = FileList["spec/**/*_spec.rb"]
10
+ end
11
+
12
+
13
+ require "yard"
14
+ require "yard/rake/yardoc_task"
15
+ YARD::Rake::YardocTask.new do |t|
16
+ t.files = ["lib/**/*.rb"]
17
+ t.options = []
18
+ t.options << "--debug" << "--verbose" if $trace
19
+ end
data/calexcer.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'calexcer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "calexcer"
8
+ spec.version = Calexcer::VERSION
9
+ spec.authors = ["sekizo"]
10
+ spec.email = ["sekizoworld@mac.com"]
11
+ spec.summary = %q{Convert excel sheet to object as calendar.}
12
+ spec.description = %q{Convert excel sheet to object as calendar.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '~> 2.1'
22
+
23
+ spec.add_dependency "spreadsheet", "~> 0.9.7", '>= 0.9.7'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "guard"
29
+ spec.add_development_dependency "guard-rspec"
30
+ spec.add_development_dependency "yard"
31
+ end
data/lib/calexcer.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "calexcer/version"
2
+
3
+ Dir.glob(File.join(File.dirname(__FILE__), "/**/*.rb")).each do |entry|
4
+ require entry
5
+ end
6
+
7
+ module Calexcer
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,24 @@
1
+ require "spreadsheet"
2
+
3
+ module Calexcer
4
+ class Book
5
+ attr_reader :path
6
+
7
+ def initialize(path)
8
+ self.path = path
9
+ end
10
+
11
+ def book
12
+ @book ||= Spreadsheet.open(self.path, "rb")
13
+ end
14
+
15
+ def sheets
16
+ self.book.worksheets.collect{ |c| Calexcer::Sheet.new(c) }
17
+ end
18
+
19
+ #--------------------#
20
+ protected
21
+
22
+ attr_writer :path
23
+ end
24
+ end
@@ -0,0 +1,66 @@
1
+ require "nkf"
2
+
3
+ module Calexcer
4
+ class Cell
5
+ EXCEL_DATE_START = DateTime.new(1900,1,1).freeze
6
+
7
+ attr_reader :cell
8
+ attr_accessor :year, :month
9
+
10
+ def initialize(cell, year: nil, month: nil)
11
+ super()
12
+ self.cell = cell
13
+ today = Date.today
14
+ self.year = year||today.year
15
+ self.month = month||today.month
16
+ end
17
+
18
+ def value
19
+ case self.cell
20
+ when Date
21
+ self.cell.to_date
22
+ when String
23
+ value_as_string(self.cell)
24
+ when Numeric
25
+ value_as_date(self.cell)
26
+ when Spreadsheet::Formula
27
+ value_as_formula(self.cell.value)
28
+ end
29
+ end
30
+
31
+ #--------------------#
32
+ protected
33
+
34
+ attr_writer :cell
35
+
36
+ #--------------------#
37
+ private
38
+
39
+ def value_as_date(cell_value)
40
+ begin
41
+ Date.new(self.year, self.month, cell_value)
42
+ rescue ArgumentError => e
43
+ EXCEL_DATE_START + cell_value - 2
44
+ end
45
+ end
46
+
47
+ def value_as_formula(cell_value)
48
+ case cell_value
49
+ when String
50
+ value_as_string(cell_value)
51
+ else
52
+ value_as_date(cell_value)
53
+ end
54
+ end
55
+
56
+ def value_as_string(value)
57
+ v = NKF::nkf('-WwZ1', value)
58
+ case v
59
+ when /^[0-9]+/
60
+ value_as_date(v.match(/^[0-9]+/).to_s.to_i)
61
+ else
62
+ value
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,7 @@
1
+ module Calexcer
2
+ class MethodNotImplementedError < StandardError
3
+ def message
4
+ "method not implemented"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,109 @@
1
+ module Calexcer
2
+ module Loopable
3
+ attr_reader :current_row, :current_col
4
+ attr_reader :x, :y
5
+
6
+ attr_accessor :year, :month
7
+
8
+ #--------------------#
9
+ protected
10
+
11
+ attr_accessor :row_start, :row_end, :col_start, :col_end
12
+
13
+ attr_writer :current_row, :current_col
14
+ attr_writer :x, :y
15
+
16
+ attr_reader :current_date
17
+ attr_accessor :current_year, :current_month
18
+
19
+ def initialize_year_month(year: nil, month: nil)
20
+ today = Date.today
21
+ self.year = year||today.year
22
+ self.month = month||today.month
23
+ end
24
+
25
+ def current_date=(date)
26
+ @current_date = date
27
+ if date.is_a?(Date)
28
+ self.current_year = date.year
29
+ self.current_month = date.year
30
+ else
31
+ self.current_year = self.year
32
+ self.current_month = self.month
33
+ end
34
+ end
35
+
36
+ def current_cell
37
+ cell = self.cell(self.current_row, self.current_col)
38
+ cell.year = self.year
39
+ cell.month = self.month
40
+ cell
41
+ end
42
+
43
+ def loop(&block)
44
+ raise Calexcer::MethodNotImplementedError
45
+ end
46
+
47
+ def loop_vertical(&block)
48
+ loop_will_start
49
+ (self.col_start..self.col_end).each do |col|
50
+ horizontal_loop_unit_will_start(col)
51
+ (self.row_start..self.row_end).each do |row|
52
+ vertical_loop_unit_will_start(row)
53
+ yield(self.current_cell)
54
+ vertical_loop_unit_will_end
55
+ end
56
+ vertical_loop_unit_did_end
57
+ horizontal_loop_unit_will_end
58
+ end
59
+ horizontal_loop_unit_did_end
60
+ loop_did_end
61
+ end
62
+
63
+ def loop_horizontal(&block)
64
+ loop_will_start
65
+ (self.row_start..self.row_end).each do |row|
66
+ vertical_loop_unit_will_start(row)
67
+ (self.col_start..self.col_end).each do |col|
68
+ horizontal_loop_unit_will_start(col)
69
+ yield(self.current_cell)
70
+ horizontal_loop_unit_will_end
71
+ end
72
+ horizontal_loop_unit_did_end
73
+ vertical_loop_unit_will_end
74
+ end
75
+ vertical_loop_unit_did_end
76
+ loop_did_end
77
+ end
78
+
79
+ def loop_will_start
80
+ dimensions
81
+ end
82
+
83
+ def loop_did_end
84
+ end
85
+
86
+ def horizontal_loop_unit_will_start(col)
87
+ self.current_col = col
88
+ self.x = self.current_col - self.col_start
89
+ end
90
+
91
+ def horizontal_loop_unit_will_end
92
+ end
93
+
94
+ def horizontal_loop_unit_did_end
95
+ end
96
+
97
+ def vertical_loop_unit_will_start(row)
98
+ @current_row = row
99
+ @y = @current_row - @row_start
100
+ end
101
+
102
+ def vertical_loop_unit_will_end
103
+ end
104
+
105
+ def vertical_loop_unit_did_end
106
+ end
107
+
108
+ end
109
+ end
@@ -0,0 +1,45 @@
1
+ require "calexcer/sheetable"
2
+ require "calexcer/cell"
3
+
4
+ module Calexcer
5
+ class Sheet
6
+ include Calexcer::Sheetable
7
+
8
+ def self.sheet_class_name(name)
9
+ _name = []
10
+ "#{name}".split("/").each do |layer|
11
+ _name << layer.sub(/^(.)/) {|char| char.upcase }.gsub(/_(.)/) {|char| char.upcase.sub(/_/, "") }
12
+ end
13
+
14
+ "Calexcer::" + _name.join('::')
15
+ end
16
+
17
+ def initialize(sheet)
18
+ self.sheet = sheet
19
+ end
20
+
21
+ def cell(row, col, cell_class: Calexcer::Cell)
22
+ cell_class.new(self.sheet[row, col])
23
+ end
24
+
25
+ #--------------------#
26
+ private
27
+
28
+ def sheet_class(name)
29
+ self.class.sheet_class_name(name)
30
+ end
31
+
32
+ def method_missing(name, *args, &block)
33
+ begin
34
+ if Calexcer.const_defined?(sheet_class(name))
35
+ Calexcer.const_get(sheet_class(name)).new(self.sheet, *args)
36
+ else
37
+ self.sheet.__send__(name, *args, &block)
38
+ end
39
+ rescue => e
40
+ super
41
+ end
42
+ end
43
+
44
+ end # class Sheet
45
+ end # module Calexcer
@@ -0,0 +1,78 @@
1
+ require "calexcer/sheet"
2
+ require "calexcer/loopable"
3
+
4
+ module Calexcer
5
+ class HorizontalSheet < Calexcer::Sheet
6
+ include Calexcer::Loopable
7
+
8
+ attr_accessor :year, :month
9
+
10
+ def initialize(sheet, year: nil, month: nil)
11
+ super(sheet)
12
+ self.initialize_year_month(year: year, month: month)
13
+ end
14
+
15
+ def to_hash(ignore_header: true)
16
+ self.events = {}
17
+ self.dates = {}
18
+
19
+ self.loop do |cell|
20
+ case cell.value
21
+ when Date
22
+ self.cell_as_date(cell.value)
23
+ when String
24
+ self.cell_as_string(cell.value, dates[self.x])
25
+ end
26
+ end
27
+
28
+ self.events
29
+ end
30
+
31
+ #--------------------#
32
+ protected
33
+
34
+ attr_accessor :current_event
35
+ attr_accessor :events, :dates
36
+
37
+ def cell_as_date(date)
38
+ self.current_date = date
39
+ self.dates[self.x] = date
40
+ end
41
+
42
+ def cell_as_string(string, date)
43
+ case
44
+ when string.empty?
45
+ when event_definition?(string)
46
+ self.current_event = string
47
+ else
48
+ if (date) && (self.current_event)
49
+ self.events[date] ||= []
50
+ self.events[date] << self.current_event
51
+ end
52
+ end
53
+ end
54
+
55
+ def loop(&block)
56
+ self.loop_horizontal(&block)
57
+ end
58
+
59
+ def horizontal_loop_unit_will_start(col)
60
+ super(col)
61
+ self.current_year = self.year
62
+ self.current_month = self.month
63
+ end
64
+
65
+ def horizontal_loop_unit_did_end
66
+ super
67
+ self.current_event = nil
68
+ end
69
+
70
+ #--------------------#
71
+ private
72
+
73
+ def event_definition?(string)
74
+ (self.current_event.nil?) && (self.x == 0) && (! string.empty?)
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,75 @@
1
+ require "calexcer/sheet"
2
+ require "calexcer/loopable"
3
+
4
+ module Calexcer
5
+ class VerticalSheet < Calexcer::Sheet
6
+ include Calexcer::Loopable
7
+
8
+ def initialize(sheet, year: nil, month: nil)
9
+ super(sheet)
10
+ self.initialize_year_month(year: year, month: month)
11
+ end
12
+
13
+ def to_hash(ignore_header: true)
14
+ self.ignore_header = ignore_header
15
+ self.events = {}
16
+
17
+ self.loop do |cell|
18
+ if (self.ignore_header) && (! cell.value.nil?)
19
+ self.ignore_header = false
20
+ else
21
+ case cell.value
22
+ when Date
23
+ self.cell_as_date(cell.value)
24
+ else
25
+ self.cell_as_string(cell.value, self.current_date)
26
+ end
27
+ end
28
+ end
29
+
30
+ self.events
31
+ end
32
+
33
+ #--------------------#
34
+ protected
35
+
36
+ attr_accessor :events
37
+ attr_accessor :ignore_header
38
+
39
+ def add_event(date, event)
40
+ return nil if (date.nil?)||(event.nil?)
41
+ self.events[date] ||= []
42
+ self.events[date] << event
43
+ end
44
+
45
+ def cell_as_date(date)
46
+ @dates ||= {}
47
+ @dates[self.current_row] = date
48
+ self.current_date = date
49
+ end
50
+
51
+ def cell_as_string(string, date)
52
+ self.add_event(self.current_date, string)
53
+ end
54
+
55
+ def loop(&block)
56
+ self.loop_vertical(&block)
57
+ end
58
+
59
+ def vertical_loop_unit_will_start(row)
60
+ super(row)
61
+ self.current_year = self.year
62
+ self.current_month = self.month
63
+
64
+ @dates ||= {}
65
+ self.current_date = @dates[row] unless @dates[row].nil?
66
+
67
+ end
68
+
69
+ def vertical_loop_unit_did_end
70
+ super
71
+ self.current_date = nil
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,46 @@
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
@@ -0,0 +1,3 @@
1
+ module Calexcer
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe Calexcer::Book do
4
+ let(:sample) { Calexcer::Samples[:vertical] }
5
+ let(:calexcer) { described_class.new(sample) }
6
+
7
+ describe "#path" do
8
+ example "get path" do
9
+ expect(calexcer.path).to eq(sample)
10
+ end
11
+ end
12
+
13
+ describe "#book" do
14
+ example "get spreadsheet instance" do
15
+ expect do
16
+ calexcer.book
17
+ end.not_to raise_error
18
+ end
19
+ end
20
+
21
+ describe "#sheets" do
22
+ example "get an Array" do
23
+ expect(calexcer.sheets).to be_a(Array)
24
+ end
25
+
26
+ example "includes Calexcer::Sheetable" do
27
+ calexcer.sheets.each do |sheet|
28
+ expect(sheet).to be_a(Calexcer::Sheetable)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require "spec_helper"
2
+
3
+ describe Calexcer::Cell do
4
+ let(:sample) { Calexcer::Samples[:vertical] }
5
+ let(:calexcer) { Calexcer::Book.new(sample) }
6
+ let(:sheet) { calexcer.sheets.first }
7
+
8
+ let(:target) { described_class.new(sheet[0, 0], year: 2014, month: 8) }
9
+ describe "#value" do
10
+ context "nill cell" do
11
+ before { allow(target).to receive(:cell) { nil } }
12
+ example("return nil") { expect(target.value).to be_nil }
13
+ end
14
+
15
+ context "Date cell" do
16
+ before { allow(target).to receive(:cell) { DateTime.new(target.year, target.month, 1) } }
17
+ example("return Date") { expect(target.value).to be_a(Date) }
18
+ example("not return DateTime") { expect(target.value).not_to be_a(DateTime) }
19
+ end
20
+
21
+ context "Float cell" do
22
+ let(:day) { 2.0 }
23
+ before { allow(target).to receive(:cell) { day } }
24
+ example("return Date") { expect(target.value).to be_a(Date) }
25
+ example("return the date") { expect(target.value.day).to eq day }
26
+ end
27
+
28
+ context "Integer cell" do
29
+ let(:day) { 3 }
30
+ before { allow(target).to receive(:cell) { day } }
31
+ example("return Date") { expect(target.value).to be_a(Date) }
32
+ example("return the date") { expect(target.value.day).to eq day }
33
+ end
34
+
35
+ context "Spreadsheet::Formula cell" do
36
+ let(:sample_cell) { { pos: { row: 8, col: 1 }, value: Date.new(2014, 8, 4) } }
37
+ let(:target) { described_class.new(sheet[sample_cell[:pos][:row], sample_cell[:pos][:col]], year: 2014, month: 8) }
38
+ example("return Date") { expect(target.value).to be_a(Date) }
39
+ example("return the date") { expect(target.value).to eq sample_cell[:value] }
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe Calexcer::Loopable do
4
+
5
+ end
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
3
+ describe Calexcer::HorizontalSheet do
4
+ let(:sample) { Calexcer::Samples[:horizontal] }
5
+ let(:calexcer) { Calexcer::Book.new(sample) }
6
+ let(:sheet) { calexcer.sheets.first.horizontal_sheet }
7
+
8
+ example "Loopable" do
9
+ expect(sheet).to be_a(Calexcer::Loopable)
10
+ end
11
+
12
+ describe "#to_hash" do
13
+ example "get Hash calendar" do
14
+ expect(sheet.to_hash).to be_a(Hash)
15
+ end
16
+
17
+ example "get calendar" do
18
+ events = sheet.to_hash
19
+
20
+ expect(events[Date.new(2014, 8, 3)]).to be_include("sunday game")
21
+ expect(events[Date.new(2014, 8, 31)]).to be_include("live")
22
+ end
23
+ end
24
+
25
+ describe "#to_reversed_hash" do
26
+ example "get reversed Hash calendar" do
27
+ expect(sheet.to_r_hash).to be_a(Hash)
28
+ end
29
+
30
+ example "get calendar" do
31
+ events = sheet.to_r_hash
32
+
33
+ expect(events["sunday game"]).to be_include(Date.new(2014, 8, 3))
34
+ expect(events["sunday game"].size).to eq 5
35
+ expect(events["live"]).to be_include(Date.new(2014, 8, 31))
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe Calexcer::VerticalSheet do
4
+ let(:sample) { Calexcer::Samples[:vertical_merged_cell] }
5
+ let(:calexcer) { Calexcer::Book.new(sample) }
6
+ let(:sheet) { calexcer.sheets.first.vertical_sheet }
7
+
8
+ context "merged cell calendar" do
9
+ describe "#to_hash" do
10
+ example "get merged cell events" do
11
+ hash = sheet.to_hash
12
+ date = Date.new(2014, 9, 7)
13
+ events = hash[date]
14
+
15
+ expect(events).to be_include("[0,0]9/7")
16
+ expect(events).to be_include("[1,1]9/7")
17
+ expect(events).to be_include("[2,2]9/7")
18
+ end
19
+
20
+ example "block to get non-events" do
21
+ expect(sheet.to_hash.collect{|k,v| v}.flatten).not_to be_include("Description of the calendar")
22
+ end
23
+ end # describe "#to_hash"
24
+ end # context "merged cell calendar"
25
+ end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ describe Calexcer::VerticalSheet do
4
+ let(:sample) { Calexcer::Samples[:vertical] }
5
+ let(:calexcer) { Calexcer::Book.new(sample) }
6
+ let(:sheet) { calexcer.sheets.first.vertical_sheet }
7
+
8
+ example "Loopable" do
9
+ expect(sheet).to be_a(Calexcer::Loopable)
10
+ end
11
+
12
+ describe "#to_hash" do
13
+ example "get Hash calendar" do
14
+ expect(sheet.to_hash).to be_a(Hash)
15
+ end
16
+
17
+ example "get events" do
18
+ expect(sheet.to_hash[Date.new(2014,8,1)]).to be_include("My birthday")
19
+ expect(sheet.to_hash[Date.new(2014,8,27)]).to be_include("My wife's birthday")
20
+ expect(sheet.to_hash[Date.new(2014,8,13)]).to be_include("My friend's birthday")
21
+ expect(sheet.to_hash[Date.new(2014,8,31)]).to be_include("My favorite artist's live")
22
+ expect(sheet.to_hash[Date.new(2014,8,15)]).to be_include("World War 2 end")
23
+ end
24
+
25
+ example "block to get non-events" do
26
+ expect(sheet.to_hash.collect{|k,v| v}.flatten).not_to be_include("Description of the calendar")
27
+ end
28
+ end # describe "#to_hash"
29
+
30
+ describe "#to_reversed_hash" do
31
+ example "get hash" do
32
+ expect(sheet.to_reversed_hash).to be_a(Hash)
33
+ end
34
+
35
+ example "get dates" do
36
+ events = sheet.to_r_hash
37
+ expect(events["My birthday"]).to be_include(Date.new(2014, 8, 1))
38
+ expect(events["My wife's birthday"]).to be_include(Date.new(2014, 8, 27))
39
+ expect(events["My friend's birthday"]).to be_include(Date.new(2014, 8, 13))
40
+ expect(events["My favorite artist's live"]).to be_include(Date.new(2014, 8, 31))
41
+ expect(events["World War 2 end"]).to be_include(Date.new(2014, 8, 15))
42
+ end
43
+
44
+ example "block to get non-events" do
45
+ events = sheet.to_r_hash
46
+ expect(events["Description of the calendar"]).to be_nil
47
+ end
48
+
49
+ end # describe "#to_reversed_hash"
50
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe Calexcer::Sheet do
4
+ let(:sample) { Calexcer::Samples[:vertical] }
5
+ let(:calexcer) { Calexcer::Book.new(sample) }
6
+ let(:sheet) { calexcer.sheets.first }
7
+
8
+ example "sheetable" do
9
+ expect(sheet).to be_a(Calexcer::Sheetable)
10
+ end
11
+
12
+ describe ".sheet_class_name" do
13
+ example "get sheet class name" do
14
+ expect(described_class.sheet_class_name("dummy")).to eq "Calexcer::Dummy"
15
+ expect(described_class.sheet_class_name("dummy/layered_class")).to eq "Calexcer::Dummy::LayeredClass"
16
+ end
17
+ end
18
+
19
+ describe "#vertical_sheet" do
20
+ example "get a VerticalSheet" do
21
+ expect(sheet.vertical_sheet).to be_a(Calexcer::VerticalSheet)
22
+ end
23
+ end
24
+
25
+ describe "#horizontal_sheet" do
26
+ example "get a HorizontalSheet" do
27
+ expect(sheet.horizontal_sheet).to be_a(Calexcer::HorizontalSheet)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Calexcer::Sheetable do
4
+ let(:sample) { Calexcer::Samples[:vertical] }
5
+ let(:calexcer) { Calexcer::Book.new(sample) }
6
+ let(:sheet) { calexcer.sheets.first }
7
+
8
+ describe ".to_hash" do
9
+ example "raise Calexcer::MethodNotImplementedError" do
10
+ expect do
11
+ sheet.to_hash
12
+ end.to raise_exception(Calexcer::MethodNotImplementedError)
13
+ end
14
+ end
15
+
16
+ describe ".to_reversed_hash" do
17
+ example "raise Calexcer::MethodNotImplementedError" do
18
+ expect do
19
+ sheet.to_reversed_hash
20
+ end.to raise_exception(Calexcer::MethodNotImplementedError)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Calexcer do
4
+ example 'has a version number' do
5
+ expect(Calexcer::VERSION).not_to be nil
6
+ end
7
+ end
8
+
Binary file
Binary file
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'calexcer'
3
+
4
+ Calexcer::Root = File.expand_path('../..', __FILE__)
5
+ Calexcer::SampleDir = File.join(Calexcer::Root, "spec/sample")
6
+
7
+ Calexcer::Samples = {}
8
+ Calexcer::Samples[:vertical] = File.join(Calexcer::SampleDir, "vertical_calendar.xls")
9
+ Calexcer::Samples[:horizontal] = File.join(Calexcer::SampleDir, "horizontal_calendar.xls")
10
+
11
+ Calexcer::Samples[:vertical_merged_cell] = File.join(Calexcer::SampleDir, "vertical_calendar_merged_cell.xls")
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: calexcer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - sekizo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spreadsheet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.7
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.7
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.7
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.6'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: guard
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: guard-rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: yard
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: Convert excel sheet to object as calendar.
118
+ email:
119
+ - sekizoworld@mac.com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - ".rspec"
126
+ - ".travis.yml"
127
+ - Gemfile
128
+ - Guardfile
129
+ - LICENSE.txt
130
+ - README.md
131
+ - Rakefile
132
+ - calexcer.gemspec
133
+ - lib/calexcer.rb
134
+ - lib/calexcer/book.rb
135
+ - lib/calexcer/cell.rb
136
+ - lib/calexcer/errors/method_not_implemented_error.rb
137
+ - lib/calexcer/loopable.rb
138
+ - lib/calexcer/sheet.rb
139
+ - lib/calexcer/sheet/horizontal_sheet.rb
140
+ - lib/calexcer/sheet/vertical_sheet.rb
141
+ - lib/calexcer/sheetable.rb
142
+ - lib/calexcer/version.rb
143
+ - spec/lib/calexcer/book_spec.rb
144
+ - spec/lib/calexcer/cell_spec.rb
145
+ - spec/lib/calexcer/loopable_spec.rb
146
+ - spec/lib/calexcer/sheet/horizontal_sheet_spec.rb
147
+ - spec/lib/calexcer/sheet/vertical_sheet_merged_cell_spec.rb
148
+ - spec/lib/calexcer/sheet/vertical_sheet_spec.rb
149
+ - spec/lib/calexcer/sheet_spec.rb
150
+ - spec/lib/calexcer/sheetable_spec.rb
151
+ - spec/lib/calexcer_spec.rb
152
+ - spec/sample/horizontal_calendar.xls
153
+ - spec/sample/vertical_calendar.xls
154
+ - spec/sample/vertical_calendar_merged_cell.xls
155
+ - spec/spec_helper.rb
156
+ homepage: ''
157
+ licenses:
158
+ - MIT
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - "~>"
167
+ - !ruby/object:Gem::Version
168
+ version: '2.1'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.2.2
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Convert excel sheet to object as calendar.
180
+ test_files:
181
+ - spec/lib/calexcer/book_spec.rb
182
+ - spec/lib/calexcer/cell_spec.rb
183
+ - spec/lib/calexcer/loopable_spec.rb
184
+ - spec/lib/calexcer/sheet/horizontal_sheet_spec.rb
185
+ - spec/lib/calexcer/sheet/vertical_sheet_merged_cell_spec.rb
186
+ - spec/lib/calexcer/sheet/vertical_sheet_spec.rb
187
+ - spec/lib/calexcer/sheet_spec.rb
188
+ - spec/lib/calexcer/sheetable_spec.rb
189
+ - spec/lib/calexcer_spec.rb
190
+ - spec/sample/horizontal_calendar.xls
191
+ - spec/sample/vertical_calendar.xls
192
+ - spec/sample/vertical_calendar_merged_cell.xls
193
+ - spec/spec_helper.rb
194
+ has_rdoc: