DSON 0.0.2 → 0.0.3
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/.gitignore +22 -22
- data/DSON.gemspec +24 -24
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +50 -48
- data/Rakefile +2 -2
- data/lib/DSON.rb +9 -9
- data/lib/DSON/value.rb +35 -33
- data/lib/DSON/value/array_value.rb +23 -23
- data/lib/DSON/value/false_value.rb +16 -16
- data/lib/DSON/value/hash_value.rb +28 -28
- data/lib/DSON/value/nil_value.rb +16 -17
- data/lib/DSON/value/numeric_value.rb +20 -20
- data/lib/DSON/value/object_value.rb +33 -0
- data/lib/DSON/value/string_value.rb +20 -20
- data/lib/DSON/value/true_value.rb +16 -16
- data/lib/DSON/version.rb +7 -7
- data/spec/dson_spec.rb +390 -369
- data/spec/lib/example_class.rb +14 -0
- metadata +16 -39
- data/lib/DSON/value/variable_value.rb +0 -14
data/.gitignore
CHANGED
@@ -1,22 +1,22 @@
|
|
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
|
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
|
data/DSON.gemspec
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'DSON/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "DSON"
|
8
|
-
spec.version = DSON::VERSION
|
9
|
-
spec.authors = ["ishakir"]
|
10
|
-
spec.email = ["imran.pshakir@gmail.com"]
|
11
|
-
spec.summary = %q{A pure-ruby DSON Serializer}
|
12
|
-
spec.homepage = ""
|
13
|
-
spec.license = "MIT"
|
14
|
-
|
15
|
-
spec.files = `git ls-files -z`.split("\x0")
|
16
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = ["lib"]
|
19
|
-
|
20
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
-
spec.add_development_dependency "rake"
|
22
|
-
spec.add_development_dependency "rspec"
|
23
|
-
spec.add_development_dependency "rubocop"
|
24
|
-
spec.add_development_dependency "magic_encoding"
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'DSON/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "DSON"
|
8
|
+
spec.version = DSON::VERSION
|
9
|
+
spec.authors = ["ishakir"]
|
10
|
+
spec.email = ["imran.pshakir@gmail.com"]
|
11
|
+
spec.summary = %q{A pure-ruby DSON Serializer}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "rubocop"
|
24
|
+
spec.add_development_dependency "magic_encoding"
|
25
25
|
end
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in DSON.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in DSON.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2014 ishakir
|
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.
|
1
|
+
Copyright (c) 2014 ishakir
|
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
CHANGED
@@ -1,48 +1,50 @@
|
|
1
|
-
# DSON
|
2
|
-
|
3
|
-
Such serialization! Totally pure-ruby also completely DSON. Wow!
|
4
|
-
|
5
|
-
Currently known deficiencies:
|
6
|
-
* Number handling (needs to be octal, currently treated as string)
|
7
|
-
|
8
|
-
## Installation
|
9
|
-
|
10
|
-
Add this line to your application's Gemfile:
|
11
|
-
|
12
|
-
gem 'DSON'
|
13
|
-
|
14
|
-
And then execute:
|
15
|
-
|
16
|
-
$ bundle
|
17
|
-
|
18
|
-
Or install it yourself as:
|
19
|
-
|
20
|
-
$ gem install DSON
|
21
|
-
|
22
|
-
## Usage
|
23
|
-
|
24
|
-
Currently supports a ruby hash and array data structure and outputs it's representation in DSON ([Doge Serialized Object notation](http://dogeon.org/)). By way of an example, try:
|
25
|
-
|
26
|
-
require 'DSON'
|
27
|
-
|
28
|
-
puts DSON.such_serialize_wow({
|
29
|
-
ruby: 'pure',
|
30
|
-
supports: [
|
31
|
-
'hash',
|
32
|
-
'array'
|
33
|
-
]
|
34
|
-
})
|
35
|
-
|
36
|
-
This should output:
|
37
|
-
|
38
|
-
such "ruby" is "pure", "supports" is so "hash" also "array" many wow
|
39
|
-
|
40
|
-
Correct to the DSON spec
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
1
|
+
# DSON
|
2
|
+
|
3
|
+
Such serialization! Totally pure-ruby also completely DSON. Wow!
|
4
|
+
|
5
|
+
Currently known deficiencies:
|
6
|
+
* Number handling (needs to be octal, currently treated as string)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'DSON'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install DSON
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Currently supports a ruby object, hash and array data structure and outputs it's representation in DSON ([Doge Serialized Object notation](http://dogeon.org/)). By way of an example, try:
|
25
|
+
|
26
|
+
require 'DSON'
|
27
|
+
|
28
|
+
puts DSON.such_serialize_wow({
|
29
|
+
ruby: 'pure',
|
30
|
+
supports: [
|
31
|
+
'hash',
|
32
|
+
'array'
|
33
|
+
]
|
34
|
+
})
|
35
|
+
|
36
|
+
This should output:
|
37
|
+
|
38
|
+
such "ruby" is "pure", "supports" is so "hash" also "array" many wow
|
39
|
+
|
40
|
+
Correct to the DSON spec.
|
41
|
+
|
42
|
+
Try it out with custom ruby objects too!
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( https://github.com/[my-github-username]/DSON/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
data/lib/DSON.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'DSON/version'
|
3
|
-
require 'DSON/value'
|
4
|
-
|
5
|
-
module DSON
|
6
|
-
def self.such_serialize_wow(subject)
|
7
|
-
DSON::Value.new(subject).such_serialize_wow
|
8
|
-
end
|
9
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/version'
|
3
|
+
require 'DSON/value'
|
4
|
+
|
5
|
+
module DSON
|
6
|
+
def self.such_serialize_wow(subject)
|
7
|
+
DSON::Value.new(subject).such_serialize_wow
|
8
|
+
end
|
9
|
+
end
|
data/lib/DSON/value.rb
CHANGED
@@ -1,33 +1,35 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'DSON/value/hash_value'
|
3
|
-
require 'DSON/value/array_value'
|
4
|
-
require 'DSON/value/string_value'
|
5
|
-
require 'DSON/value/nil_value'
|
6
|
-
require 'DSON/value/true_value'
|
7
|
-
require 'DSON/value/false_value'
|
8
|
-
require 'DSON/value/numeric_value'
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
return
|
17
|
-
return
|
18
|
-
return
|
19
|
-
return
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value/hash_value'
|
3
|
+
require 'DSON/value/array_value'
|
4
|
+
require 'DSON/value/string_value'
|
5
|
+
require 'DSON/value/nil_value'
|
6
|
+
require 'DSON/value/true_value'
|
7
|
+
require 'DSON/value/false_value'
|
8
|
+
require 'DSON/value/numeric_value'
|
9
|
+
require 'DSON/value/object_value'
|
10
|
+
|
11
|
+
module DSON
|
12
|
+
module Value
|
13
|
+
SPACE = %q( )
|
14
|
+
|
15
|
+
def self.new(value)
|
16
|
+
return HashValue.new(value) if value.respond_to? :keys
|
17
|
+
return ArrayValue.new(value) if value.respond_to? :each
|
18
|
+
return NilValue.instance if value.nil?
|
19
|
+
return TrueValue.instance if value.is_a? TrueClass
|
20
|
+
return FalseValue.instance if value.is_a? FalseClass
|
21
|
+
# return NumericValue.new(value) if value.is_a? Fixnum
|
22
|
+
return StringValue.new(value) if value.is_a? String
|
23
|
+
ObjectValue.new(value)
|
24
|
+
end
|
25
|
+
|
26
|
+
def reduce(list, potential_joiners)
|
27
|
+
list.each_with_index.reduce('') do |acc, (element, index)|
|
28
|
+
is_last = (index == list.size - 1)
|
29
|
+
|
30
|
+
formed_string = is_last ? element : element + potential_joiners.sample
|
31
|
+
acc + formed_string + SPACE
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module DSON
|
3
|
-
module Value
|
4
|
-
class ArrayValue
|
5
|
-
include Value
|
6
|
-
|
7
|
-
POTENTIAL_JOINERS = [' and' , ' also']
|
8
|
-
|
9
|
-
attr_reader :value
|
10
|
-
|
11
|
-
def initialize(value)
|
12
|
-
@value = value
|
13
|
-
end
|
14
|
-
|
15
|
-
def such_serialize_wow
|
16
|
-
content = value.map do |arr_elem|
|
17
|
-
Value.new(arr_elem).such_serialize_wow
|
18
|
-
end
|
19
|
-
'so ' + reduce(content, POTENTIAL_JOINERS) + 'many'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module DSON
|
3
|
+
module Value
|
4
|
+
class ArrayValue
|
5
|
+
include Value
|
6
|
+
|
7
|
+
POTENTIAL_JOINERS = [' and' , ' also']
|
8
|
+
|
9
|
+
attr_reader :value
|
10
|
+
|
11
|
+
def initialize(value)
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def such_serialize_wow
|
16
|
+
content = value.map do |arr_elem|
|
17
|
+
Value.new(arr_elem).such_serialize_wow
|
18
|
+
end
|
19
|
+
'so ' + reduce(content, POTENTIAL_JOINERS) + 'many'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'DSON/value'
|
2
|
-
|
3
|
-
require 'singleton'
|
4
|
-
|
5
|
-
module DSON
|
6
|
-
module Value
|
7
|
-
class FalseValue
|
8
|
-
include Value
|
9
|
-
include Singleton
|
10
|
-
|
11
|
-
def such_serialize_wow
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require 'DSON/value'
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module DSON
|
6
|
+
module Value
|
7
|
+
class FalseValue
|
8
|
+
include Value
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
def such_serialize_wow
|
12
|
+
'no'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'DSON/value'
|
3
|
-
|
4
|
-
module DSON
|
5
|
-
module Value
|
6
|
-
class HashValue
|
7
|
-
include Value
|
8
|
-
|
9
|
-
POTENTIAL_PUNCTUATION = %w(, . ! ?)
|
10
|
-
|
11
|
-
attr_reader :value
|
12
|
-
|
13
|
-
def initialize(value)
|
14
|
-
@value = value
|
15
|
-
end
|
16
|
-
|
17
|
-
def such_serialize_wow
|
18
|
-
strings = value.keys.map do |key|
|
19
|
-
key_str = StringValue.new(key).such_serialize_wow
|
20
|
-
value_str = Value.new(value[key]).such_serialize_wow
|
21
|
-
|
22
|
-
%Q(#{key_str} is #{value_str})
|
23
|
-
end
|
24
|
-
'such ' + reduce(strings, POTENTIAL_PUNCTUATION) + 'wow'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'DSON/value'
|
3
|
+
|
4
|
+
module DSON
|
5
|
+
module Value
|
6
|
+
class HashValue
|
7
|
+
include Value
|
8
|
+
|
9
|
+
POTENTIAL_PUNCTUATION = %w(, . ! ?)
|
10
|
+
|
11
|
+
attr_reader :value
|
12
|
+
|
13
|
+
def initialize(value)
|
14
|
+
@value = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def such_serialize_wow
|
18
|
+
strings = value.keys.map do |key|
|
19
|
+
key_str = StringValue.new(key).such_serialize_wow
|
20
|
+
value_str = Value.new(value[key]).such_serialize_wow
|
21
|
+
|
22
|
+
%Q(#{key_str} is #{value_str})
|
23
|
+
end
|
24
|
+
'such ' + reduce(strings, POTENTIAL_PUNCTUATION) + 'wow'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|