jeremyf-comma_pile 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/VERSION.yml +1 -1
- data/comma_pile.gemspec +4 -2
- data/lib/comma_pile/line_parser.rb +6 -0
- data/test/comma_pile/line_parser_test.rb +29 -0
- metadata +3 -1
data/VERSION.yml
CHANGED
data/comma_pile.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{comma_pile}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jeremy Friesen"]
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/comma_pile/line_parser.rb",
|
27
27
|
"lib/comma_pile/pivot_node.rb",
|
28
28
|
"lib/comma_pile/report.rb",
|
29
|
+
"test/comma_pile/line_parser_test.rb",
|
29
30
|
"test/comma_pile_test.rb",
|
30
31
|
"test/fixtures/report.csv",
|
31
32
|
"test/test_helper.rb"
|
@@ -36,7 +37,8 @@ Gem::Specification.new do |s|
|
|
36
37
|
s.rubygems_version = %q{1.3.4}
|
37
38
|
s.summary = %q{Video Stats for an onstreammedia.com log}
|
38
39
|
s.test_files = [
|
39
|
-
"test/
|
40
|
+
"test/comma_pile/line_parser_test.rb",
|
41
|
+
"test/comma_pile_test.rb",
|
40
42
|
"test/test_helper.rb",
|
41
43
|
"examples/example_line_parser.rb"
|
42
44
|
]
|
@@ -1,5 +1,11 @@
|
|
1
1
|
module CommaPile
|
2
2
|
class LineParser
|
3
|
+
def self.define_attribute(name, index = nil, cast_class = nil, &block)
|
4
|
+
raise ArgumentError, "You must specify either an :index parameter or a :block for retriving the column information" if (block_given? && index)
|
5
|
+
define_method(name, &block) and return if block_given?
|
6
|
+
define_method(name) { line[index] } and return if index.is_a?(Integer)
|
7
|
+
end
|
8
|
+
|
3
9
|
def self.with(line)
|
4
10
|
yield(new(line))
|
5
11
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require '../test_helper'
|
2
|
+
|
3
|
+
class CommaPile::LineParserTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context 'define column' do
|
6
|
+
should 'allow column method to be defined via an integer' do
|
7
|
+
klass = Class.new(CommaPile::LineParser) {
|
8
|
+
define_attribute :name, 1
|
9
|
+
}
|
10
|
+
|
11
|
+
assert_equal 'b', klass.new(['a','b','c']).name
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'allow column to be set by a block' do
|
15
|
+
klass = Class.new(CommaPile::LineParser) {
|
16
|
+
define_attribute(:name) { self[1] + (self[2] * 2) }
|
17
|
+
}
|
18
|
+
assert_equal 'bcc', klass.new(['a','b','c']).name
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'raise exception if both index and block are passed' do
|
22
|
+
assert_raises ArgumentError do
|
23
|
+
Class.new(CommaPile::LineParser) {
|
24
|
+
define_attribute(:name, 1) { self[1] + (self[2] * 2) }
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeremyf-comma_pile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Friesen
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/comma_pile/line_parser.rb
|
37
37
|
- lib/comma_pile/pivot_node.rb
|
38
38
|
- lib/comma_pile/report.rb
|
39
|
+
- test/comma_pile/line_parser_test.rb
|
39
40
|
- test/comma_pile_test.rb
|
40
41
|
- test/fixtures/report.csv
|
41
42
|
- test/test_helper.rb
|
@@ -67,6 +68,7 @@ signing_key:
|
|
67
68
|
specification_version: 3
|
68
69
|
summary: Video Stats for an onstreammedia.com log
|
69
70
|
test_files:
|
71
|
+
- test/comma_pile/line_parser_test.rb
|
70
72
|
- test/comma_pile_test.rb
|
71
73
|
- test/test_helper.rb
|
72
74
|
- examples/example_line_parser.rb
|