emmental 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: efa86cc4764813860a2f134ffa30b00fb52300bd
4
+ data.tar.gz: 63adc657e89fdaf4f66b1fb7cdfd612aee302200
5
+ SHA512:
6
+ metadata.gz: 945975bf0d79483223be5a0a30843ae5478c649195394dfaa266d88fbcccd1141ec9b475032ee4fc3e8a0bc6fb5a9f3f149143dfccd28714ad8b3eb84bc09d2c
7
+ data.tar.gz: ed4046434854e50dede681a2f0f1df094afc02a534ff77dc25708371e0e4ba1f2058e698862125891c0793d712748bf55cb8b5d5330af9f3d82f47b239e97a2b
@@ -0,0 +1,23 @@
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
+ .rspec
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.0.0
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in emmental.gemspec
4
+ gemspec
@@ -0,0 +1,6 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 OSA Shunsuke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Emmental
2
+
3
+ [![Build Status](https://travis-ci.org/s-osa/emmental.svg?branch=master)](https://travis-ci.org/s-osa/emmental)
4
+
5
+ Sparse table gem.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'emmental'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install emmental
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/emmental/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'emmental/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "emmental"
8
+ spec.version = Emmental::VERSION
9
+ spec.authors = ["OSA Shunsuke"]
10
+ spec.email = ["hhelibebcnofnenamg@gmail.com"]
11
+ spec.summary = %q{Sparse table gem}
12
+ spec.description = %q{Sparse table gem}
13
+ spec.homepage = "https://github.com/s-osa/emmental"
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.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "guard-rspec"
24
+ end
@@ -0,0 +1,34 @@
1
+ require "emmental/version"
2
+ require "emmental/headers"
3
+ require "emmental/row"
4
+
5
+ class Emmental
6
+ include Enumerable
7
+
8
+ attr_accessor :headers
9
+ attr_reader :rows
10
+
11
+ def initialize(headers=[])
12
+ @headers = Emmental::Headers.new(headers)
13
+ @rows = []
14
+ end
15
+
16
+ def each
17
+ @rows.each{|row| yield(row) }
18
+ end
19
+
20
+ def add_row(hash)
21
+ @rows << Emmental::Row.new(hash, @headers)
22
+ end
23
+ alias :<< :add_row
24
+
25
+ def to_a(options={})
26
+ array = (options[:headers] == false) ? [] : [@headers]
27
+
28
+ @rows.each do |row|
29
+ array << @headers.map{|header| row.to_h[header] }
30
+ end
31
+
32
+ array
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ class Emmental
2
+ class Headers < Array
3
+ def initialize(headers=[])
4
+ super([headers].flatten)
5
+ end
6
+
7
+ def add_header(header)
8
+ self << header unless self.include?(header)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ class Emmental
2
+ class Row
3
+ attr_accessor :headers
4
+
5
+ def initialize(hash, headers)
6
+ @hash = hash
7
+ @headers = headers
8
+
9
+ hash.each_key do |header|
10
+ @headers.add_header(header)
11
+ end
12
+ end
13
+
14
+ def to_h
15
+ @hash
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class Emmental
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Emmental::Headers do
4
+ describe "initialize" do
5
+ it "should return an instance of Array subclass" do
6
+ actual = Emmental::Headers.new
7
+ expect(actual).to be_a(Array)
8
+ end
9
+
10
+ context "without headers" do
11
+ it "should return an instance of Emmental::Headers" do
12
+ actual = Emmental::Headers.new
13
+ expect(actual).to be_an_instance_of(Emmental::Headers)
14
+ end
15
+ end
16
+
17
+ context "with headers Array" do
18
+ it "should return an instance of Emmental::Headers" do
19
+ actual = Emmental::Headers.new(["foo", "bar"])
20
+ expect(actual).to be_an_instance_of(Emmental::Headers)
21
+ end
22
+ end
23
+
24
+ context "with header String" do
25
+ it "should return an instance of Emmental::Headers" do
26
+ actual = Emmental::Headers.new("single_header")
27
+ expect(actual).to be_an_instance_of(Emmental::Headers)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#add_header" do
33
+ it "should add new header" do
34
+ headers = Emmental::Headers.new
35
+ expect{headers.add_header("hoge")}.to change(headers, :size).by(1)
36
+ end
37
+
38
+ it "should not add exixting header" do
39
+ headers = Emmental::Headers.new
40
+ headers.add_header("hoge")
41
+ expect{headers.add_header("hoge")}.not_to change(headers, :size)
42
+ end
43
+ end
44
+
45
+ describe "#to_a" do
46
+ it "should return Array" do
47
+ array = ["foo", "bar"]
48
+ headers = Emmental::Headers.new(array)
49
+ expect(headers.to_a).to eq array
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Emmental::Row do
4
+ let(:row){ Emmental::Row.new({foo: 1, "bar" => 2}, Emmental::Headers.new) }
5
+
6
+ describe "initialize" do
7
+ it "should return an instance of Emmental::Row" do
8
+ expect(row).to be_an_instance_of(Emmental::Row)
9
+ end
10
+
11
+ it "should add headers to Emmental::Headers" do
12
+ expect(row.headers.size).to be > 0
13
+
14
+ row.headers.each do |header|
15
+ expect(row.headers).to include(header)
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "#headers" do
21
+ it "should return an instance of Emmental::Headers" do
22
+ expect(row.headers).to be_an_instance_of(Emmental::Headers)
23
+ end
24
+ end
25
+
26
+ describe "#to_h" do
27
+ it "should return Hash" do
28
+ hash = {foo: 1, "bar" => 2}
29
+ row = Emmental::Row.new(hash, Emmental::Headers.new)
30
+ expect(row.to_h).to eq hash
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe Emmental do
4
+ describe "initialize" do
5
+ context "without headers" do
6
+ it "should return an instance of Emmental" do
7
+ actual = Emmental.new
8
+ expect(actual).to be_an_instance_of(Emmental)
9
+ end
10
+ end
11
+
12
+ context "with headers" do
13
+ it "should return an instance of Emmental" do
14
+ actual = Emmental.new(["foo", "bar"])
15
+ expect(actual).to be_an_instance_of(Emmental)
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "headers" do
21
+ let(:emmental){ Emmental.new }
22
+
23
+ describe "#headers" do
24
+ it "should return an instance of Emmental::Headers" do
25
+ expect(emmental.headers).to be_an_instance_of(Emmental::Headers)
26
+ end
27
+
28
+ it "should contain all headers" do
29
+ emmental << {foo: "bar"}
30
+ emmental << {fizz: "buzz"}
31
+ expect(emmental.headers).to eq [:foo, :fizz]
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ describe "rows" do
38
+ let(:emmental){ Emmental.new }
39
+
40
+ describe "#<<" do
41
+ it "should increase number of rows" do
42
+ expect{ emmental << {foo: "bar"} }.to change(emmental.rows, :size).by(1)
43
+ end
44
+ end
45
+
46
+ describe "#rows" do
47
+ it "should return Array" do
48
+ expect(emmental.rows).to be_an_instance_of(Array)
49
+ end
50
+
51
+ it "should contain instances of Emmental::Row" do
52
+ emmental << {foo: "bar"}
53
+ emmental.rows.each do |row|
54
+ expect(row).to be_an_instance_of(Emmental::Row)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ describe "#to_a" do
61
+ before do
62
+ @emmental = Emmental.new(["a_header"])
63
+ @emmental << {foo: 1, "bar" => 2}
64
+ @emmental << {fizz: 3, buzz: 5}
65
+ @emmental << {foo: 1}
66
+ @header = ["a_header", :foo, "bar", :fizz, :buzz]
67
+ @rows = [
68
+ [nil, 1, 2, nil, nil],
69
+ [nil, nil, nil, 3, 5],
70
+ [nil, 1, nil, nil, nil]
71
+ ]
72
+ end
73
+
74
+ it "should return rectangle array with headers" do
75
+ expected = [@header].concat(@rows)
76
+ expect(@emmental.to_a).to eq expected
77
+ end
78
+
79
+ it "should return rectangle array without headers" do
80
+ expected = @rows
81
+ expect(@emmental.to_a(headers: false)).to eq expected
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,4 @@
1
+ project_root = File.join(File.dirname(__FILE__), "..")
2
+ $: << project_root
3
+
4
+ require 'lib/emmental'
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emmental
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - OSA Shunsuke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Sparse table gem
56
+ email:
57
+ - hhelibebcnofnenamg@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - Guardfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - emmental.gemspec
70
+ - lib/emmental.rb
71
+ - lib/emmental/headers.rb
72
+ - lib/emmental/row.rb
73
+ - lib/emmental/version.rb
74
+ - spec/emmental/headers_spec.rb
75
+ - spec/emmental/row_spec.rb
76
+ - spec/emmental_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/s-osa/emmental
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Sparse table gem
102
+ test_files:
103
+ - spec/emmental/headers_spec.rb
104
+ - spec/emmental/row_spec.rb
105
+ - spec/emmental_spec.rb
106
+ - spec/spec_helper.rb