cbhpm_table 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2665ab80eeac088dfe2d6d672bd8360d6e80fb2a
4
+ data.tar.gz: b5abeb212cef6adc12891bcab5d1fd9690ae0980
5
+ SHA512:
6
+ metadata.gz: 698385dfea783bb86373d1deaca68755a7181c3692359351543dc354b7d30793c13269274d38acf7ad757f08c3ca147a9d7ff9291f8b73e5ba1c0b0876bb1320
7
+ data.tar.gz: 8963d7e4abc34600d20bf6ee25f2407d2613868a0e514a3dbbc5fdfc25be94ab12f14866d38b0658d5b6aa98b97b7b50f98d0bdfac40e95efe64878af4102b1a
data/.gitignore ADDED
@@ -0,0 +1,24 @@
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
+ **.DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cbhpm_table.gemspec
4
+ gemspec
5
+
6
+ gem 'roo'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Abinoam Praxedes Marques Jr.
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,49 @@
1
+ # CBHPMTable
2
+
3
+ A simple gem to wrap the CBHPM excel files from Associação Brasileira de Medicina.
4
+
5
+ **CBHPM**:
6
+
7
+ * Classificação Brasileira Hierarquizada de Procedimentos Médicos (pt)
8
+ * Brazilian Hierarchical Classification of Medical Procedures (en)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'cbhpm_table'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install cbhpm_table
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ cbhpm_table = CBHPMTable.new "CBHPM 2012.xlsx"
28
+
29
+ cbhpm_table.headers
30
+ #=> { "code"=>"ID do Procedimento", "name"=>"Descrição do Procedimento", "cir_size"=>nil, "uco"=>"Custo Operac.", "aux_qty"=>"Nº de Aux.", "an_size"=>"Porte Anestés."}
31
+
32
+ cbhpm_table.row(2)
33
+ #=> {"code"=>"10101012", "name"=>"Em consultório (no horário normal ou preestabelecido)", "cir_size"=>"2B", "uco"=>nil, "aux_qty"=>nil, "an_size"=>nil})}
34
+
35
+ cbhpm_table.rows
36
+ #=> # Returns an Array of Rows (as individual Hashes)
37
+
38
+ cbhpm_table.each_row do |row|
39
+ # do whatever with the row
40
+ end
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/[my-github-username]/cbhpm_table/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 'cbhpm_table/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cbhpm_table"
8
+ spec.version = CBHPMTable::VERSION
9
+ spec.authors = ["Abinoam Praxedes Marques Jr."]
10
+ spec.email = ["abinoam@gmail.com"]
11
+ spec.summary = %q{CBHPM Table. A simple wrapper around the CBHPM excel files.}
12
+ spec.description = %q{It takes a CBHPM Excel spreadsheet file and give convenience methods to deal with it. }
13
+ spec.homepage = "https://github.com/abinoam/cbhpm_table"
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 "rspec"
24
+ end
@@ -0,0 +1,3 @@
1
+ class CBHPMTable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,89 @@
1
+ require "cbhpm_table/version"
2
+
3
+ require 'roo'
4
+
5
+ class CBHPMTable
6
+ attr_reader :roo, :headers_hash
7
+
8
+ def initialize(cbhpm_path, headers_hash = nil)
9
+ cbhpm_file_extension = File.extname(cbhpm_path)
10
+ cbhpm_file_basename = File.basename(cbhpm_path)
11
+
12
+ roo_class = ROO_CLASS_FOR_EXTENSION[cbhpm_file_extension]
13
+ @roo = roo_class.new(cbhpm_path)
14
+ @headers_hash = headers_hash || HEADER_FOR_FILE[cbhpm_file_basename]
15
+ raise "Can't find predefined headers for #{cbhpm_path}" unless @headers_hash
16
+ end
17
+
18
+ def headers
19
+ row(first_row_index)
20
+ end
21
+
22
+ def first_row_index
23
+ roo.first_row
24
+ end
25
+
26
+ def row(row_index)
27
+ import_row(roo.row(row_index))
28
+ end
29
+
30
+ def import_row(row_array)
31
+ imported_row = Hash.new
32
+
33
+ headers_hash.each do |col, name|
34
+ imported_row[name] = row_array[col]
35
+ end
36
+
37
+ imported_row
38
+ end
39
+
40
+ def rows
41
+ each_row.to_a
42
+ end
43
+
44
+ def each_row
45
+ return to_enum(:each_row) unless block_given?
46
+ roo_enum = roo.to_enum(:each)
47
+ _skip_header = roo_enum.next
48
+ loop do
49
+ yield import_row(roo_enum.next)
50
+ end
51
+ end
52
+
53
+ private :first_row_index, :import_row
54
+ end
55
+
56
+ class CBHPMTable
57
+ module HeaderFormat
58
+ CBHPM5a =
59
+ { 0 => "code",
60
+ 1 => "name",
61
+ 4 => "cir_size",
62
+ 5 => "uco",
63
+ 6 => "aux_qty",
64
+ 7 => "an_size" }
65
+
66
+ CBHPM2010 =
67
+ { 0 => "code",
68
+ 1 => "name",
69
+ 4 => "cir_size",
70
+ 5 => "uco",
71
+ 6 => "aux_qty",
72
+ 7 => "an_size" }
73
+
74
+ CBHPM2012 =
75
+ { 4 => "code",
76
+ 5 => "name",
77
+ 8 => "cir_size",
78
+ 9 => "uco",
79
+ 10 => "aux_qty",
80
+ 11 => "an_size" }
81
+ end
82
+
83
+ HEADER_FOR_FILE =
84
+ { "CBHPM 5¶ Ediá∆o.xls" => HeaderFormat::CBHPM5a,
85
+ "CBHPM 2010 separada.xls" => HeaderFormat::CBHPM2010,
86
+ "CBHPM 2012.xlsx" => HeaderFormat::CBHPM2012 }
87
+
88
+ ROO_CLASS_FOR_EXTENSION = { ".xls" => Roo::Excel, ".xlsx" => Roo::Excelx }
89
+ end
@@ -0,0 +1,63 @@
1
+ require 'rspec'
2
+ require 'cbhpm_table'
3
+
4
+ describe CBHPMTable do
5
+ let(:cbhpm_table) do
6
+ CBHPMTable.new("spec/cbhpm/CBHPM_cut_for_testing.xlsx",
7
+ CBHPMTable::HeaderFormat::CBHPM2012)
8
+ end
9
+
10
+ it { expect(cbhpm_table).to respond_to(:headers) }
11
+
12
+ describe "#headers_hash - the format hash for headers" do
13
+ it { expect(cbhpm_table.headers_hash).to eq CBHPMTable::HeaderFormat::CBHPM2012 }
14
+ end
15
+
16
+ describe "#headers - the first line of the CBHPM Table" do
17
+ it { expect(cbhpm_table.headers).to be_instance_of(Hash) }
18
+ it { expect(cbhpm_table.headers).to eq({ "code"=>"ID do Procedimento",
19
+ "name"=>"Descrição do Procedimento",
20
+ "cir_size"=>nil,
21
+ "uco"=>"Custo Operac.",
22
+ "aux_qty"=>"Nº de Aux.",
23
+ "an_size"=>"Porte Anestés."}) }
24
+ end
25
+
26
+ describe "#row - any row" do
27
+ let(:row) { cbhpm_table.row(2) }
28
+
29
+ it { expect(row).to be_instance_of(Hash) }
30
+ it { expect(row).to eq({"code"=>"10101012",
31
+ "name"=>"Em consultório (no horário normal ou preestabelecido)",
32
+ "cir_size"=>"2B",
33
+ "uco"=>nil,
34
+ "aux_qty"=>nil,
35
+ "an_size"=>nil})}
36
+ end
37
+
38
+ describe "#each_row" do
39
+ describe "returns an Enumerator when no block given" do
40
+ it { expect(cbhpm_table.each_row).to be_instance_of Enumerator }
41
+ end
42
+
43
+ describe "iterates through each row" do
44
+ specify do
45
+ cbhpm_table.each_row do |row|
46
+ expect(row).to be_instance_of Hash
47
+ expect(row['code']).to match /\d{8}/
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#rows" do
54
+ let(:rows) { cbhpm_table.rows }
55
+
56
+ it { expect(rows).to be_instance_of Array }
57
+
58
+ describe ".first" do
59
+ it { expect(rows.first).to be_instance_of Hash }
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,92 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+
17
+ require 'cbhpm_table'
18
+
19
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
20
+ RSpec.configure do |config|
21
+ # rspec-expectations config goes here. You can use an alternate
22
+ # assertion/expectation library such as wrong or the stdlib/minitest
23
+ # assertions if you prefer.
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+ end
34
+
35
+ # rspec-mocks config goes here. You can use an alternate test double
36
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
37
+ config.mock_with :rspec do |mocks|
38
+ # Prevents you from mocking or stubbing a method that does not exist on
39
+ # a real object. This is generally recommended, and will default to
40
+ # `true` in RSpec 4.
41
+ mocks.verify_partial_doubles = true
42
+ end
43
+
44
+ # The settings below are suggested to provide a good initial experience
45
+ # with RSpec, but feel free to customize to your heart's content.
46
+ =begin
47
+ # These two settings work together to allow you to limit a spec run
48
+ # to individual examples or groups you care about by tagging them with
49
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
50
+ # get run.
51
+ config.filter_run :focus
52
+ config.run_all_when_everything_filtered = true
53
+
54
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
55
+ # For more details, see:
56
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
57
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
59
+ config.disable_monkey_patching!
60
+
61
+ # This setting enables warnings. It's recommended, but in some cases may
62
+ # be too noisy due to issues in dependencies.
63
+ config.warnings = true
64
+
65
+ # Many RSpec users commonly either run the entire suite or an individual
66
+ # file, and it's useful to allow more verbose output when running an
67
+ # individual spec file.
68
+ if config.files_to_run.one?
69
+ # Use the documentation formatter for detailed output,
70
+ # unless a formatter has already been configured
71
+ # (e.g. via a command-line flag).
72
+ config.default_formatter = 'doc'
73
+ end
74
+
75
+ # Print the 10 slowest examples and example groups at the
76
+ # end of the spec run, to help surface which specs are running
77
+ # particularly slow.
78
+ config.profile_examples = 10
79
+
80
+ # Run specs in random order to surface order dependencies. If you find an
81
+ # order dependency and want to debug it, you can fix the order by providing
82
+ # the seed, which is printed after each run.
83
+ # --seed 1234
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+ =end
92
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cbhpm_table
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Abinoam Praxedes Marques Jr.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-28 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: 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: 'It takes a CBHPM Excel spreadsheet file and give convenience methods
56
+ to deal with it. '
57
+ email:
58
+ - abinoam@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - cbhpm_table.gemspec
70
+ - lib/cbhpm_table.rb
71
+ - lib/cbhpm_table/version.rb
72
+ - spec/cbhpm/cbhpm_cut_for_testing.xlsx
73
+ - spec/cbhpm_table_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/abinoam/cbhpm_table
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: CBHPM Table. A simple wrapper around the CBHPM excel files.
99
+ test_files:
100
+ - spec/cbhpm/cbhpm_cut_for_testing.xlsx
101
+ - spec/cbhpm_table_spec.rb
102
+ - spec/spec_helper.rb