wankel 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 820fc80e5cf50976025731b5151b1ba941a46758
4
- data.tar.gz: 8db0022010b5da08d31b52df372918b7de07c73d
3
+ metadata.gz: 794731e10604a40d87557559c974422920b468a0
4
+ data.tar.gz: b328c5d3230268990c5d34004c6e8ae885e2d437
5
5
  SHA512:
6
- metadata.gz: 2f1846a7234dade3c2afb24a19be695c270ae8f8d61df172527f7afba27d6a77be2df2e9783cb2d7b12f0db779507e86e6ffc0be36f68ac564312d5fc0e23dac
7
- data.tar.gz: c38cad9f0d72a5786542ae6983de3c6957e5f6e51b521773e51283bea5c481059e30c1453b201e02148f8f8f646a6e75f976bf0394d893dd8971f4bd758c0f8d
6
+ metadata.gz: 468bfdbee4e692305cceb4647c298d218cc43f4ec3278890254da41fc497657b1ac5300d92bab4f215a0d723bf65f9141778ffba1365a27da2957ed781739650
7
+ data.tar.gz: 857c6ad778dc3d6a5917c03ccbac6c35531bdfeba8fefde80af1f0f30c0bfaf28f1954774932c46afc187c9f28ca2bca08e2110ae272def85772502560c48a64
data/.gitignore CHANGED
@@ -9,3 +9,4 @@ coverage
9
9
  *.log
10
10
  Makefile
11
11
  tmp
12
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sunstone.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  <a href="http://wanklerb.com">![Wankel](/logo.png)</a>
2
2
 
3
+ [![Circle CI](https://circleci.com/gh/malomalo/wankel/tree/master.svg?style=svg)](https://circleci.com/gh/malomalo/wankel/tree/master)
4
+
3
5
  **Wankel** is a Ruby gem that provides C bindings to the
4
6
  [YAJL 2](http://lloyd.github.io/yajl/) C Library.
5
7
 
@@ -78,11 +80,11 @@ encoder = Wankel::SaxEncoder.new(output)
78
80
  encoder.map_open
79
81
  encoder.string("key")
80
82
  encoder.number(123)
83
+ encoder.string("type")
84
+ encoder.value("value-determined-by-method")
81
85
  encoder.map_close
82
86
  encoder.complete
83
- output.rewind
84
- output.read
85
- # => '{"key":123}'
87
+ output.string # => '{"key":123,"type":"value-determined-by-method"}'
86
88
  ```
87
89
 
88
90
  Parsing Options
data/Rakefile CHANGED
@@ -1,3 +1,7 @@
1
+ require 'bundler/setup'
2
+ require "bundler/gem_tasks"
3
+ Bundler.require(:development)
4
+
1
5
  require "rake/extensiontask"
2
6
  require "rake/testtask"
3
7
  require "rubygems/package_task"
@@ -61,5 +65,3 @@ task :c_coverage do
61
65
  SimpleCov::ResultMerger.store_result(data)
62
66
  end
63
67
  end
64
-
65
- # https://github.com/defunkt/sdoc-helpers
data/lib/wankel.rb CHANGED
@@ -16,4 +16,29 @@ class Wankel
16
16
  :validate_utf8 => false,
17
17
  :escape_solidus => false
18
18
  }
19
+ end
20
+
21
+ class Wankel::SaxEncoder
22
+
23
+ def value(val)
24
+ case val
25
+ when NilClass
26
+ null
27
+ when TrueClass, FalseClass
28
+ boolean(val)
29
+ when Numeric
30
+ number(val)
31
+ when String
32
+ string(val)
33
+ when Array
34
+ array_open
35
+ val.each {|v| value(v) }
36
+ array_close
37
+ when Hash
38
+ map_open
39
+ val.each {|k, v| string(k.to_s); value(v) }
40
+ map_close
41
+ end
42
+ end
43
+
19
44
  end
@@ -1,7 +1,17 @@
1
+ require 'test_helper'
1
2
  require 'stringio'
2
3
 
3
4
  class Wankel::SaxEncoderTest < Minitest::Test
4
5
 
6
+ def setup
7
+ @output = StringIO.new
8
+ @encoder = Wankel::SaxEncoder.new(@output)
9
+ end
10
+
11
+ def assert_output(value)
12
+ assert_equal(value, @output.string)
13
+ end
14
+
5
15
  test 'default inherited from Wankel' do
6
16
  encoder = Wankel::SaxEncoder.new(StringIO.new)
7
17
  assert_equal(Wankel::DEFAULTS, encoder.instance_variable_get("@options"))
@@ -13,77 +23,127 @@ class Wankel::SaxEncoderTest < Minitest::Test
13
23
  end
14
24
 
15
25
  test "number" do
16
- output = StringIO.new
17
- encoder = Wankel::SaxEncoder.new(output)
18
- encoder.number(1234)
19
- encoder.complete
20
- assert_equal("1234", output.string)
26
+ @encoder.number(1234)
27
+ @encoder.complete
28
+
29
+ assert_output("1234")
21
30
  end
22
31
 
23
32
  test "string" do
24
- output = StringIO.new
25
- encoder = Wankel::SaxEncoder.new(output)
26
- encoder.string("hello world")
27
- encoder.complete
28
- assert_equal('"hello world"', output.string)
33
+ @encoder.string("hello world")
34
+ @encoder.complete
35
+
36
+ assert_output('"hello world"')
29
37
  end
30
38
 
31
39
  test "null" do
32
- output = StringIO.new
33
- encoder = Wankel::SaxEncoder.new(output)
34
- encoder.null
35
- encoder.complete
36
- assert_equal("null", output.string)
40
+ @encoder.null
41
+ @encoder.complete
42
+
43
+ assert_output("null")
37
44
  end
38
45
 
39
46
  test "boolean(false)" do
40
- output = StringIO.new
41
- encoder = Wankel::SaxEncoder.new(output)
42
- encoder.boolean(false)
43
- encoder.complete
44
- assert_equal("false", output.string)
47
+ @encoder.boolean(false)
48
+ @encoder.complete
49
+
50
+ assert_output("false")
45
51
  end
46
52
 
47
53
  test "boolean(true)" do
48
- output = StringIO.new
49
- encoder = Wankel::SaxEncoder.new(output)
50
- encoder.boolean(true)
51
- encoder.complete
52
- assert_equal("true", output.string)
54
+ @encoder.boolean(true)
55
+ @encoder.complete
56
+
57
+ assert_output("true")
53
58
  end
54
59
 
55
60
  test "map_open" do
56
- output = StringIO.new
57
- encoder = Wankel::SaxEncoder.new(output)
58
- encoder.map_open
59
- encoder.complete
60
- assert_equal("{", output.string)
61
+ @encoder.map_open
62
+ @encoder.complete
63
+
64
+ assert_output("{")
61
65
  end
62
66
 
63
67
  test "map_close" do
64
- output = StringIO.new
65
- encoder = Wankel::SaxEncoder.new(output)
66
- encoder.map_open
67
- encoder.map_close
68
- encoder.complete
69
- assert_equal("{}", output.string)
68
+ @encoder.map_open
69
+ @encoder.map_close
70
+ @encoder.complete
71
+
72
+ assert_output("{}")
70
73
  end
71
74
 
72
75
  test "array_open" do
73
- output = StringIO.new
74
- encoder = Wankel::SaxEncoder.new(output)
75
- encoder.array_open
76
- encoder.complete
77
- assert_equal("[", output.string)
76
+ @encoder.array_open
77
+ @encoder.complete
78
+
79
+ assert_output("[")
78
80
  end
79
81
 
80
82
  test "array_close" do
81
- output = StringIO.new
82
- encoder = Wankel::SaxEncoder.new(output)
83
- encoder.array_open
84
- encoder.array_close
85
- encoder.complete
86
- assert_equal("[]", output.string)
83
+ @encoder.array_open
84
+ @encoder.array_close
85
+ @encoder.complete
86
+
87
+ assert_output("[]")
88
+ end
89
+
90
+ test "value(NUMBER)" do
91
+ @encoder.value(123)
92
+ @encoder.complete
93
+
94
+ assert_output("123")
95
+ end
96
+
97
+ test "value(STRING)" do
98
+ @encoder.value("hello")
99
+ @encoder.complete
100
+
101
+ assert_output("\"hello\"")
87
102
  end
103
+
104
+ test "value(NIL)" do
105
+ @encoder.value(nil)
106
+ @encoder.complete
107
+
108
+ assert_output("null")
109
+ end
110
+
111
+ test "value(BOOLEAN)" do
112
+ @encoder.value(true)
113
+ @encoder.complete
114
+
115
+ assert_output("true")
116
+
117
+ @output.rewind
118
+ @encoder.value(false)
119
+ @encoder.complete
120
+
121
+ assert_output("true")
122
+ end
123
+
124
+ test "value(ARRAY)" do
125
+ @encoder.value([])
126
+ @encoder.complete
127
+
128
+ assert_output("[]")
129
+ end
130
+
131
+ test "value(ARRAY_WITH_VALUES)" do
132
+ @encoder.value([1, "hello", nil, false, true, 45.21, {:key => 'val'}])
133
+ @encoder.complete
134
+
135
+ assert_output("[1,\"hello\",null,false,true,45.21,{\"key\":\"val\"}]")
136
+ end
137
+
138
+ test "value(HASH)" do
139
+ @encoder.value(:one => 'one', :two => 2, :three => true, :four => nil, 5 => [45.21])
140
+ @encoder.complete
141
+
142
+ assert_output('{"one":"one","two":2,"three":true,"four":null,"5":[45.21]}')
143
+ end
144
+
145
+ end
146
+ __END__
147
+ test "map_open" do
148
+ test "map_close" do
88
149
 
89
- end
data/wankel.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'wankel'
3
- s.version = '0.3.0'
3
+ s.version = '0.3.1'
4
4
  s.licenses = ['MIT']
5
5
  s.authors = ['Jon Bracy']
6
6
  s.email = ['jonbracy@gmail.com']
@@ -19,11 +19,4 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency 'minitest', '~> 5.3'
20
20
  s.add_development_dependency 'minitest-reporters', '~> 1.0'
21
21
  s.add_development_dependency 'mocha', '~> 1.1'
22
- end
23
-
24
- # spec.requirements << 'libmagick, v6.0'
25
- # spec.extra_rdoc_files = ['README', 'doc/user-guide.txt']
26
- # s.metadata = { "issue_tracker" => "https://example/issues" }
27
- # spec.rdoc_options << '--title' << 'Rake -- Ruby Make' <<
28
- # '--main' << 'README' <<
29
- # '--line-numbers'
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wankel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
78
  - CHANGELOG.md
79
+ - Gemfile
79
80
  - LICENSE
80
81
  - README.md
81
82
  - Rakefile
@@ -97,7 +98,6 @@ files:
97
98
  - ext/wankel/yajl_helpers.c
98
99
  - ext/wankel/yajl_helpers.h
99
100
  - lib/wankel.rb
100
- - lib/wankel/ex_sax_parser.rb
101
101
  - logo.png
102
102
  - test/encoding/encoding_test.rb
103
103
  - test/encoding/sax_encoder_test.rb
@@ -259,4 +259,3 @@ test_files:
259
259
  - test/performance.rb
260
260
  - test/test_helper.rb
261
261
  - test/wankel_test.rb
262
- has_rdoc:
@@ -1,75 +0,0 @@
1
- class Wankel::SaxParser
2
-
3
- def on_map_start
4
- puts 'start map'
5
- end
6
-
7
- def on_map_end
8
- puts 'end map'
9
- end
10
-
11
- def on_map_key(key)
12
- puts 'key'
13
- end
14
-
15
- def on_null
16
- puts "null"
17
- end
18
-
19
- def on_boolean(value)
20
- puts value
21
- end
22
-
23
- def on_integer(i)
24
- puts "integer"
25
- end
26
-
27
- def on_double(d)
28
- puts "double"
29
- end
30
-
31
- def on_string(s)
32
- puts "string"
33
- end
34
-
35
- def on_array_start
36
- puts "start array"
37
- end
38
-
39
- def on_array_end
40
- puts "end array"
41
- end
42
-
43
- end
44
-
45
-
46
- class Wankel::SaxEncoder
47
-
48
- def number
49
- end
50
-
51
- def string
52
- end
53
-
54
- def null
55
- end
56
-
57
- def bool
58
- end
59
-
60
- def map_open
61
- end
62
-
63
- def map_close
64
- end
65
-
66
- def array_open
67
- end
68
-
69
- def array_close
70
- end
71
-
72
- def complete
73
- end
74
-
75
- end