conformist 0.1.1 → 0.1.2

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.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.2 / 2012-01-19
4
+
5
+ * `Conformist::Builder` coerces enumerables into an Array. Works with Spreadsheet for conforming Microsoft Excel spreadsheets.
6
+
7
+ ## 0.1.1 / 2012-01-17
8
+
9
+ * Explicitly required `Forwardable`.
10
+
3
11
  ## 0.1.0 / 2012-01-05
4
12
 
5
13
  * Added anonymous schemas.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/tatey/conformist.png)](http://travis-ci.org/tatey/conformist)
4
4
 
5
- Bend CSVs to your will with declarative schemas. Map one or many columns, preprocess cells and lazily enumerate. Declarative schemas are easier to understand, quicker to setup and independent of I/O. Use CSV (Formally FasterCSV) or any array of array-like data structure.
5
+ Bend CSVs to your will with declarative schemas. Map one or many columns, preprocess cells and lazily enumerate. Declarative schemas are easier to understand, quicker to setup and independent of I/O. Use [CSV](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/csv/rdoc/CSV.html) (Formally [FasterCSV](https://rubygems.org/gems/fastercsv)), [Spreadsheet](https://rubygems.org/gems/spreadsheet) or any array of array-like data structure.
6
6
 
7
7
  ![](http://f.cl.ly/items/00191n3O1J2E1a342F1L/conformist.jpg)
8
8
 
@@ -75,7 +75,31 @@ db = SQLite3::Database.new 'transmitters.db'
75
75
  end
76
76
  ```
77
77
 
78
- For **more examples** see `test/fixtures`, `test/schemas` and `test/unit/integration_test.rb`.
78
+ Open a Microsoft Excel spreadsheet and declare a schema.
79
+
80
+ ``` ruby
81
+ require 'conformist'
82
+ require 'spreadsheet'
83
+
84
+ book = Spreadsheet.open '~/states.xls'
85
+ sheet = book.worksheet 0
86
+ schema = Conformist.new do
87
+ column :state, 0, 1 do |values|
88
+ "#{values.first}, #{values.last}"
89
+ end
90
+ column :capital, 2
91
+ end
92
+ ```
93
+
94
+ Print each state's attributes to standard out.
95
+
96
+ ``` ruby
97
+ schema.conform(sheet).each do |state|
98
+ $stdout.puts state.attributes
99
+ end
100
+ ```
101
+
102
+ For more examples see [test/fixtures](https://github.com/tatey/conformist/tree/master/test/fixtures), [test/schemas](https://github.com/tatey/conformist/tree/master/test/schemas) and [test/unit/integration_test.rb](https://github.com/tatey/conformist/blob/master/test/unit/integration_test.rb).
79
103
 
80
104
  ## Installation
81
105
 
data/conformist.gemspec CHANGED
@@ -25,8 +25,9 @@ EOS
25
25
 
26
26
  s.required_ruby_version = '>= 1.8.7'
27
27
 
28
- s.add_development_dependency 'rake'
29
28
  s.add_development_dependency 'minitest'
29
+ s.add_development_dependency 'rake'
30
+ s.add_development_dependency 'spreadsheet'
30
31
 
31
32
  s.files = `git ls-files`.split("\n")
32
33
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -8,8 +8,8 @@ module Conformist
8
8
  self.preprocessor = preprocessor
9
9
  end
10
10
 
11
- def values_in array
12
- values = array.values_at(*indexes).map do |value|
11
+ def values_in enumerable
12
+ values = Array(enumerable).values_at(*indexes).map do |value|
13
13
  if value.respond_to? :strip
14
14
  value.strip
15
15
  else
@@ -1,3 +1,3 @@
1
1
  module Conformist
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
Binary file
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class BuilderTest < MiniTest::Unit::TestCase
3
+ class Conformist::BuilderTest < MiniTest::Unit::TestCase
4
4
  def test_included
5
5
  assert_raises RuntimeError do
6
6
  Class.new { include Base }
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class BuilderTest < MiniTest::Unit::TestCase
3
+ class Conformist::BuilderTest < MiniTest::Unit::TestCase
4
4
  def test_call
5
5
  column = MiniTest::Mock.new
6
6
  column.expect :name, :a
@@ -1,47 +1,56 @@
1
1
  require 'helper'
2
2
 
3
- class ColumnTest < MiniTest::Unit::TestCase
3
+ class Conformist::ColumnTest < MiniTest::Unit::TestCase
4
4
  def stub_row
5
5
  ('a'..'d').to_a
6
6
  end
7
7
 
8
8
  def test_name
9
- column = Conformist::Column.new :foo
9
+ column = Column.new :foo
10
10
  assert_equal :foo, column.name
11
11
  end
12
12
 
13
13
  def test_one_index
14
- column = Conformist::Column.new :foo, 0
14
+ column = Column.new :foo, 0
15
15
  assert_equal 'a', column.values_in(stub_row)
16
16
  end
17
17
 
18
18
  def test_preprocess_with_one_index
19
- column = Conformist::Column.new(:foo, 0) { |value| value.upcase }
19
+ column = Column.new(:foo, 0) { |value| value.upcase }
20
20
  assert_equal 'A', column.values_in(stub_row)
21
21
  end
22
22
 
23
23
  def test_many_indexes
24
- column = Conformist::Column.new :foo, 1, 2, 3
24
+ column = Column.new :foo, 1, 2, 3
25
25
  assert_equal ['b', 'c', 'd'], column.values_in(stub_row)
26
26
  end
27
27
 
28
28
  def test_preprocess_with_many_indexes
29
- column = Conformist::Column.new(:foo, 1, 2, 3) { |values| values.reverse }
29
+ column = Column.new(:foo, 1, 2, 3) { |values| values.reverse }
30
30
  assert_equal ['d', 'c', 'b'], column.values_in(stub_row)
31
31
  end
32
32
 
33
33
  def test_virtual
34
- column = Conformist::Column.new(:foo) { 'a' }
34
+ column = Column.new(:foo) { 'a' }
35
35
  assert_equal 'a', column.values_in(stub_row)
36
36
  end
37
37
 
38
38
  def test_strip_whitespace
39
- column = Conformist::Column.new(:foo, 0)
39
+ column = Column.new :foo, 0
40
40
  assert_equal 'a', column.values_in([' a '])
41
41
  end
42
42
 
43
+ def test_array
44
+ mock = MiniTest::Mock.new
45
+ mock.expect :to_a, ['a']
46
+ column = Column.new :foo, 0
47
+ assert_equal 'a', column.values_in(['a'])
48
+ assert_equal 'a', column.values_in('a')
49
+ assert_equal 'a', column.values_in(mock)
50
+ end
51
+
43
52
  def test_nil
44
- column = Conformist::Column.new(:foo, 0)
53
+ column = Column.new :foo, 0
45
54
  assert_nil column.values_in([])
46
55
  end
47
56
  end
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class HashStructTest < MiniTest::Unit::TestCase
3
+ class Conformist::HashStructTest < MiniTest::Unit::TestCase
4
4
  def test_initialize
5
5
  assert_equal({:a => 1}, HashStruct.new({:a => 1}).attributes)
6
6
  assert_empty HashStruct.new.attributes
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class SchemaTest < MiniTest::Unit::TestCase
3
+ class Conformist::SchemaTest < MiniTest::Unit::TestCase
4
4
  def test_initialize_with_instance
5
5
  parent = Class.new { include Schema }.new.tap { |d| d.columns = [0] }
6
6
  child1 = Class.new { include Schema }.new(parent).tap { |d| d.columns << 1 }
@@ -2,14 +2,18 @@ require 'csv'
2
2
  require 'helper'
3
3
  require 'schemas/acma'
4
4
  require 'schemas/fcc'
5
+ require 'spreadsheet'
5
6
 
6
7
  class IntegrationTest < MiniTest::Unit::TestCase
8
+ def fixture filename
9
+ File.expand_path "../../fixtures/#{filename}", __FILE__
10
+ end
11
+
7
12
  def open_csv filename, options = {}
8
- path = File.expand_path "../../fixtures/#{filename}", __FILE__
9
13
  if CSV.method(:open).arity == -3 # 1.8 CSV
10
- CSV.open path, 'r', options[:col_sep]
14
+ CSV.open fixture(filename), 'r', options[:col_sep]
11
15
  else
12
- CSV.open path, options
16
+ CSV.open fixture(filename), options
13
17
  end
14
18
  end
15
19
 
@@ -31,19 +35,28 @@ class IntegrationTest < MiniTest::Unit::TestCase
31
35
  assert_equal HashStruct.new(:name => 'LOS ANGELES, CA', :callsign => 'KVTU-LP', :latitude => '34 13 38.00 N', :signtal_type => 'digital'), last
32
36
  end
33
37
 
38
+ def test_instance_with_spreadsheet
39
+ book = Spreadsheet.open fixture('states.xls')
40
+ sheet = book.worksheet 0
41
+ schema = Conformist.new { column :state, 0 }
42
+ enumerable = schema.conform sheet
43
+ last = enumerable.to_a.last
44
+ assert_equal HashStruct.new(:state => 'QLD'), last
45
+ end
46
+
34
47
  def test_instance_with_array_of_arrays
35
48
  data = Array.new.tap do |d|
36
49
  d << ['NSW', 'New South Wales', 'Sydney']
37
50
  d << ['VIC', 'Victoria', 'Melbourne']
38
51
  d << ['QLD', 'Queensland', 'Brisbane']
39
52
  end
40
- definition = Conformist.new do
53
+ schema = Conformist.new do
41
54
  column :state, 0, 1 do |values|
42
55
  "#{values.first}, #{values.last}"
43
56
  end
44
57
  column :capital, 2
45
58
  end
46
- enumerable = definition.conform data
59
+ enumerable = schema.conform data
47
60
  last = enumerable.to_a.last
48
61
  assert_equal HashStruct.new(:state => 'QLD, Queensland', :capital => 'Brisbane'), last
49
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conformist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-17 00:00:00.000000000 Z
12
+ date: 2012-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: &70205885514860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70205885514860
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rake
16
- requirement: &70138920491840 !ruby/object:Gem::Requirement
27
+ requirement: &70205885551760 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: '0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *70138920491840
35
+ version_requirements: *70205885551760
25
36
  - !ruby/object:Gem::Dependency
26
- name: minitest
27
- requirement: &70138920488020 !ruby/object:Gem::Requirement
37
+ name: spreadsheet
38
+ requirement: &70205885551340 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70138920488020
46
+ version_requirements: *70205885551340
36
47
  description: Bend CSVs to your will with declarative schemas.
37
48
  email:
38
49
  - tate@tatey.com
@@ -57,6 +68,7 @@ files:
57
68
  - lib/conformist/version.rb
58
69
  - test/fixtures/acma.csv
59
70
  - test/fixtures/fcc.txt
71
+ - test/fixtures/states.xls
60
72
  - test/helper.rb
61
73
  - test/schemas/acma.rb
62
74
  - test/schemas/fcc.rb
@@ -91,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
103
  version: '0'
92
104
  segments:
93
105
  - 0
94
- hash: 688471822358112849
106
+ hash: -2238739611496231910
95
107
  requirements: []
96
108
  rubyforge_project: conformist
97
109
  rubygems_version: 1.8.11
@@ -101,6 +113,7 @@ summary: Bend CSVs to your will with declarative schemas.
101
113
  test_files:
102
114
  - test/fixtures/acma.csv
103
115
  - test/fixtures/fcc.txt
116
+ - test/fixtures/states.xls
104
117
  - test/helper.rb
105
118
  - test/schemas/acma.rb
106
119
  - test/schemas/fcc.rb