simple_report 0.1.0

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: f98c990ab100b1bbbbfe334f4ece710ed895f682
4
+ data.tar.gz: b4f0681aaddd82c82a6731ba74670355b622cf1d
5
+ SHA512:
6
+ metadata.gz: f506009a364c546294118f3d5d97ebae95c70ff4b0d40aec84391c3fd47aba6335ffcaed42b113d2e6b8d174a529013c5e94bb1e5de3b726fa83cf2b544200ec
7
+ data.tar.gz: 4a62e6e447fee563d3befd74bc28cfc03ba311c4cec22fdecd14346f3b53bb60bd45c8a649dc898eeca7a5cdad7f9de6f131929a054de990cc960385a1b4844d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.8
5
+ - 2.3.5
6
+ - 2.4.2
7
+ - ruby-head
8
+ addons:
9
+ code_climate:
10
+ repo_token: d81350f440f981f869cc37fff76ba610a27e6b2bd442999057e9ad18100216dc
11
+ # regular test configuration
12
+ after_success:
13
+ - bundle exec codeclimate-test-reporter
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/lostapathy/simple_report" }
4
+
5
+ # Specify your gem's dependencies in simple_report.gemspec
6
+ gemspec
7
+
8
+ group :test do
9
+ gem "simplecov"
10
+ gem "codeclimate-test-reporter", "~> 1.0.0"
11
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Joe Francis
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # SimpleReports
2
+
3
+ [![Build Status](https://travis-ci.org/lostapathy/simple_report.svg?branch=master)](https://travis-ci.org/lostapathy/simple_report)
4
+ [![Code Climate](https://api.codeclimate.com/v1/badges/04ced70d7b66d1a7c42d/maintainability)](https://codeclimate.com/github/lostapathy/simple_report)
5
+ [![Test Coverage](https://codeclimate.com/github/lostapathy/simple_report/badges/coverage.svg)](https://codeclimate.com/github/lostapathy/simple_report/coverage)
6
+
7
+
8
+ simple_report is a gem for building simple reports from Enumerable collections. It was extracted from a larger application and only supports Excel exports for now, but other formats could be added.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'simple_report'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install simple_report
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests.
33
+
34
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lostapathy/simple_report.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,8 @@
1
+ require "simple_report/version"
2
+ require "simple_report/base"
3
+ require "simple_report/sheet"
4
+ require "simple_report/field"
5
+
6
+ module SimpleReport
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,70 @@
1
+ module SimpleReport
2
+ class Base
3
+ def add_format(name, format)
4
+ @formats ||= {}
5
+ @formats[name] = format
6
+ end
7
+
8
+ def initialize
9
+ @file = Tempfile.new('simple_report')
10
+ @workbook = WriteXLSX.new(@file.path)
11
+ money = @workbook.add_format
12
+ money.set_num_format('$0.00')
13
+ add_format :money, money
14
+
15
+ heading = @workbook.add_format
16
+ heading.set_bold
17
+ add_format :heading, heading
18
+
19
+ percent = @workbook.add_format
20
+ percent.set_num_format('0%')
21
+ add_format :percent, percent
22
+ end
23
+
24
+ def report_xls(*params)
25
+ report(*params)
26
+ @workbook.close
27
+ File.read @file.path
28
+ end
29
+
30
+ private
31
+
32
+ def add_sheet(name, data)
33
+ sheet = Sheet.new(name)
34
+ @fields = []
35
+ sheet = @workbook.add_worksheet(name)
36
+ yield
37
+ @sheets ||= []
38
+ @sheets << sheet
39
+
40
+ @fields.each_with_index do |f, index|
41
+ sheet.set_column(index, index, f.width)
42
+ sheet.write(0, index, f.name, @formats[:heading])
43
+ end
44
+
45
+ data.each_with_index do |ic, row|
46
+ @fields.each_with_index do |field, column|
47
+ if field.field
48
+ value = ic.send(field.field)
49
+ elsif field.value
50
+ value = field.value
51
+ elsif field.block
52
+ value = field.block.call(ic)
53
+ end
54
+ sheet.write(row + 1, column, value, find_format(field.format))
55
+ end
56
+ end
57
+ end
58
+
59
+ def field(name, field = nil, width: nil, format: nil, value: nil, &block)
60
+ rf = Field.new(name, field, width: width, format: format, value: value, &block)
61
+ @fields << rf
62
+ end
63
+
64
+ private
65
+
66
+ def find_format(format)
67
+ @formats[format]
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,14 @@
1
+ module SimpleReport
2
+ class Field
3
+ attr_reader :name, :width, :block, :format, :field, :value
4
+
5
+ def initialize(name, field, format: nil, width: 10, value: nil, &block)
6
+ @name = name
7
+ @field = field
8
+ @width = width
9
+ @value = value
10
+ @block = block
11
+ @format = format
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module SimpleReport
2
+ class Sheet
3
+ def initialize(name)
4
+ @name = name
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleReport
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "simple_report/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_report"
8
+ spec.version = SimpleReport::VERSION
9
+ spec.authors = ["Joe Francis"]
10
+ spec.email = ["joe@lostapathy.com"]
11
+
12
+ spec.summary = %q{Generate simple reports.}
13
+ spec.description = %q{Generate simple reports from Enumerable collections, from simple Arrays to ActiveRecord Collections. }
14
+ spec.homepage = "https://github.com/lostapathy/simple_report"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+
28
+ spec.add_dependency "write_xlsx", '~> 0.85.1'
29
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_report
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe Francis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-14 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: write_xlsx
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.85.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.85.1
69
+ description: 'Generate simple reports from Enumerable collections, from simple Arrays
70
+ to ActiveRecord Collections. '
71
+ email:
72
+ - joe@lostapathy.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/simple_report.rb
84
+ - lib/simple_report/base.rb
85
+ - lib/simple_report/field.rb
86
+ - lib/simple_report/sheet.rb
87
+ - lib/simple_report/version.rb
88
+ - simple_report.gemspec
89
+ homepage: https://github.com/lostapathy/simple_report
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.13
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Generate simple reports.
113
+ test_files: []