conformist 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,6 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.0.2
3
+ ## 0.0.3 / 2011-05-07
4
+
5
+ * Inheriting from a class which mixes in Conformist::Base gives you access to all of the superclasses' columns.
6
+
7
+ ## 0.0.2 / 2011-04-28
4
8
 
5
9
  * Column#values_in will be nil if the index is out of range rather than an empty string. This is consistent with CSV
6
10
  * Fixed 1.8.7 and JRuby dependancies. Gemspec will not let you specify dependancies based on the version of Ruby. Everyone gets it
data/README.markdown CHANGED
@@ -23,7 +23,7 @@ class Citizen1
23
23
  include Conformist::Base
24
24
 
25
25
  column :name, 0, 1
26
- column :address, 2 do |value|
26
+ column :city, 2 do |value|
27
27
  value.upcase
28
28
  end
29
29
  end
@@ -32,7 +32,7 @@ class Citizen2
32
32
  include Conformist::Base
33
33
 
34
34
  column :name, 0
35
- column :address, 1
35
+ column :city, 1
36
36
  end
37
37
  ```
38
38
 
@@ -74,7 +74,7 @@ column :name, 0, 1
74
74
  Indexing is completely arbitrary and you can map any combination.
75
75
 
76
76
  ``` ruby
77
- column :name_and_address, 0, 2
77
+ column :name_and_city 0, 2
78
78
  ```
79
79
 
80
80
  ### Preprocessing
@@ -105,6 +105,37 @@ column :day do
105
105
  end
106
106
  ```
107
107
 
108
+ ### Inheritance
109
+
110
+ Inheriting from a class which mixes in Conformist::Base gives you access to all of the superclasses' columns.
111
+
112
+ ``` ruby
113
+ class Citizen
114
+ include Conformist::Base
115
+
116
+ column :name, 0, 1
117
+ end
118
+
119
+ class Adult < Citizen
120
+ column :category do
121
+ 'Adult'
122
+ end
123
+ end
124
+
125
+ class Child < Citizen
126
+ column :category do
127
+ 'Child'
128
+ end
129
+ end
130
+
131
+ Adult.load('adults.csv').foreach do |row|
132
+ row # => {:name => 'Tate Johnson', :category => 'Adult}
133
+ end
134
+ ```
135
+ ## Example
136
+
137
+ * https://gist.github.com/949576
138
+
108
139
  ## Compatibility
109
140
 
110
141
  * 1.9.2-p180
@@ -3,7 +3,6 @@ module Conformist
3
3
  def self.included base
4
4
  base.class_eval do
5
5
  extend ClassMethods
6
-
7
6
  attr_accessor :path
8
7
  end
9
8
  end
@@ -30,7 +29,11 @@ module Conformist
30
29
  end
31
30
 
32
31
  def columns
33
- @columns ||= []
32
+ @columns ||= if superclass.ancestors.include? Conformist::Base
33
+ superclass.columns.dup
34
+ else
35
+ []
36
+ end
34
37
  end
35
38
 
36
39
  def option value
@@ -1,3 +1,3 @@
1
1
  module Conformist
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -2,35 +2,45 @@ require 'helper'
2
2
 
3
3
  class BaseTest < MiniTest::Unit::TestCase
4
4
  def setup
5
- @klass = Class.new.tap { |klass| klass.send :include, Conformist::Base }
5
+ @class = Class.new.tap { |klass| klass.send :include, Conformist::Base }
6
6
  end
7
7
 
8
8
  def test_option
9
- @klass.option :a => 1
10
- @klass.option :b => 2
11
- assert_equal({:a => 1, :b => 2}, @klass.options)
9
+ @class.option :a => 1
10
+ @class.option :b => 2
11
+ assert_equal({:a => 1, :b => 2}, @class.options)
12
12
  end
13
13
 
14
14
  def test_column
15
- @klass.column :a, 0
16
- @klass.column :b, 1
17
- assert_equal 2, @klass.columns.size
18
- assert_instance_of Conformist::Column, @klass.columns[rand(2)]
15
+ @class.column :a, 0
16
+ @class.column :b, 1
17
+ assert_equal 2, @class.columns.size
18
+ assert_instance_of Conformist::Column, @class.columns[rand(2)]
19
+ end
20
+
21
+ def test_columns_inherit_from_superclass
22
+ subclass = Class.new @class
23
+ @class.column :a, 0
24
+ @class.column :b, 1
25
+ assert_equal @class.columns, subclass.columns
26
+ subclass.column :c, 2
27
+ subclass.column :d, 3
28
+ refute_equal @class.columns, subclass.columns
19
29
  end
20
30
 
21
31
  def test_load
22
- instance = @klass.load 'file'
32
+ instance = @class.load 'file'
23
33
  assert_equal 'file', instance.path
24
- assert_instance_of @klass, instance
34
+ assert_instance_of @class, instance
25
35
  end
26
36
 
27
37
  def test_foreach
28
38
  rows = [
29
- {:name => "CRAFERS", :callsign => "ABS2", :latitude => "34 58 49S", :signtal_type => "digital"},
30
- {:name => "CRAFERS", :callsign => "SAS7", :latitude => "34 58 57S", :signtal_type => "digital"},
31
- {:name => "CRAFERS", :callsign => "NWS9", :latitude => "34 59 02S", :signtal_type => "digital"},
32
- {:name => "CRAFERS", :callsign => "ADS10", :latitude => "34 59 02S", :signtal_type => "digital"},
33
- {:name => "CRAFERS", :callsign => "ADS10", :latitude => "34 58 57S", :signtal_type => "digital"}
39
+ {:name => "CRAFERS", :callsign => "ABS2", :latitude => "34 58 49S"},
40
+ {:name => "CRAFERS", :callsign => "SAS7", :latitude => "34 58 57S"},
41
+ {:name => "CRAFERS", :callsign => "NWS9", :latitude => "34 59 02S"},
42
+ {:name => "CRAFERS", :callsign => "ADS10", :latitude => "34 59 02S"},
43
+ {:name => "CRAFERS", :callsign => "ADS10", :latitude => "34 58 57S"}
34
44
  ]
35
45
  ACMA.load(fixture('acma.csv')).foreach do |row|
36
46
  assert_equal rows.shift, row
@@ -14,7 +14,7 @@ class ConformistTest < MiniTest::Unit::TestCase
14
14
  {:name => "SACRAMENTO, CA", :callsign => "KCSO-LD", :latitude => "38 7 10.00 N", :signtal_type => "digital"},
15
15
  {:name => "LOS ANGELES, CA", :callsign => "KVTU-LP", :latitude => "34 13 38.00 N", :signtal_type => "digital"}
16
16
  ]
17
- Conformist.foreach ACMA.load(fixture('acma.csv')), FCC.load(fixture('fcc.txt')) do |row|
17
+ Conformist.foreach ACMA::Digital.load(fixture('acma.csv')), FCC.load(fixture('fcc.txt')) do |row|
18
18
  assert_equal rows.shift, row
19
19
  end
20
20
  end
@@ -1,16 +1,24 @@
1
- class FCC
1
+ class ACMA
2
2
  include Conformist::Base
3
3
 
4
- option :col_sep => '|'
5
-
6
- column :name, 10, 11 do |values|
7
- "#{values[0].upcase}, #{values[-1]}"
4
+ option :col_sep => ','
5
+ option :quote_char => '"'
6
+
7
+ column :name, 11 do |value|
8
+ value.match(/[A-Z]+$/)[0].upcase
8
9
  end
9
10
  column :callsign, 1
10
- column :latitude, 20, 21, 22, 19 do |values|
11
- values.join(' ')
12
- end
13
- column :signtal_type do
14
- 'digital'
11
+ column :latitude, 15
12
+ end
13
+
14
+ class ACMA::Digital < ACMA
15
+ column :signtal_type do
16
+ 'digital'
17
+ end
18
+ end
19
+
20
+ class ACMA::Analogue < ACMA
21
+ column :signtal_type do
22
+ 'analogue'
15
23
  end
16
24
  end
@@ -1,15 +1,16 @@
1
- class ACMA
1
+ class FCC
2
2
  include Conformist::Base
3
3
 
4
- option :col_sep => ','
5
- option :quote_char => '"'
6
-
7
- column :name, 11 do |value|
8
- value.match(/[A-Z]+$/)[0].upcase
4
+ option :col_sep => '|'
5
+
6
+ column :name, 10, 11 do |values|
7
+ "#{values[0].upcase}, #{values[-1]}"
9
8
  end
10
9
  column :callsign, 1
11
- column :latitude, 15
12
- column :signtal_type do
10
+ column :latitude, 20, 21, 22, 19 do |values|
11
+ values.join(' ')
12
+ end
13
+ column :signtal_type do
13
14
  'digital'
14
15
  end
15
16
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: conformist
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tate Johnson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-28 00:00:00 +10:00
13
+ date: 2011-05-07 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
- hash: -1209245458572220166
100
+ hash: 3830580058108286643
101
101
  segments:
102
102
  - 0
103
103
  version: "0"