DSON 0.1.0 → 0.2.0

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.
@@ -1,47 +1,49 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'DSON/value'
3
-
4
- module DSON
5
- module Value
6
- class ArrayValue
7
- include Value
8
-
9
- def self.so_parse(options)
10
- word_array = options[:word_array]
11
- parent_array = options[:parent_array]
12
-
13
- if word_array[0] == 'many'
14
- word_array.shift
15
- return parent_array
16
- end
17
- word_array.shift unless (word_array[0] =~ /and|also/).nil?
18
-
19
- # the next value will be the value
20
- parent_array.push(DSON::Value.handle_next(options))
21
-
22
- so_parse(options)
23
- end
24
-
25
- POTENTIAL_JOINERS = [' and' , ' also']
26
-
27
- attr_reader :value
28
-
29
- def initialize(value)
30
- @value = value
31
- end
32
-
33
- def such_serialize_wow
34
- content = value.map do |arr_elem|
35
- Value.new(arr_elem).such_serialize_wow
36
- end
37
- 'so ' + reduce(content, POTENTIAL_JOINERS) + 'many'
38
- end
39
-
40
- AND_ALSO_REGEX = / and | also /
41
-
42
- def self.parse_value(value, acc_array)
43
- acc_array.push DSON.so_parse(value)
44
- end
45
- end
46
- end
47
- end
1
+ # -*- encoding : utf-8 -*-
2
+ require 'DSON/value'
3
+
4
+ module DSON
5
+ module Value
6
+ class ArrayValue
7
+ include Value
8
+
9
+ def self.so_parse(options)
10
+ word_array = options[:word_array]
11
+ parent_array = options[:parent_array]
12
+
13
+ if word_array[0] == 'many'
14
+ word_array.shift
15
+ return parent_array
16
+ end
17
+ word_array.shift unless (word_array[0] =~ /^(and|also)$/).nil?
18
+
19
+ # the next value will be the value
20
+ parent_array.push(DSON::Value.handle_next(options))
21
+
22
+ return parent_array if word_array.empty?
23
+
24
+ so_parse(options)
25
+ end
26
+
27
+ POTENTIAL_JOINERS = [' and' , ' also']
28
+
29
+ attr_reader :value
30
+
31
+ def initialize(value)
32
+ @value = value
33
+ end
34
+
35
+ def such_serialize_wow
36
+ content = value.map do |arr_elem|
37
+ Value.new(arr_elem).such_serialize_wow
38
+ end
39
+ 'so ' + reduce(content, POTENTIAL_JOINERS) + 'many'
40
+ end
41
+
42
+ AND_ALSO_REGEX = / and | also /
43
+
44
+ def self.parse_value(value, acc_array)
45
+ acc_array.push DSON.so_parse(value)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,21 +1,21 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'DSON/value'
3
-
4
- require 'singleton'
5
-
6
- module DSON
7
- module Value
8
- class FalseValue
9
- include Value
10
- include Singleton
11
-
12
- def self.so_parse
13
- false
14
- end
15
-
16
- def such_serialize_wow
17
- 'no'
18
- end
19
- end
20
- end
21
- end
1
+ # -*- encoding : utf-8 -*-
2
+ require 'DSON/value'
3
+
4
+ require 'singleton'
5
+
6
+ module DSON
7
+ module Value
8
+ class FalseValue
9
+ include Value
10
+ include Singleton
11
+
12
+ def self.so_parse
13
+ false
14
+ end
15
+
16
+ def such_serialize_wow
17
+ 'no'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,59 +1,56 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'DSON/value'
3
-
4
- module DSON
5
- module Value
6
- class HashValue
7
- include Value
8
-
9
- def self.so_parse(options)
10
- word_array = options[:word_array]
11
- parent_hash = options[:parent_hash]
12
-
13
- if word_array[0] == 'wow'
14
- word_array.shift
15
- return parent_hash
16
- end
17
- word_array.shift unless (word_array[0] =~ (/\?|\.|,|!/)).nil?
18
-
19
- string_hash = options[:string_hash]
20
-
21
- # The next value will be a key
22
- numeric_key = word_array.shift
23
- key = string_hash[numeric_key.to_i]
24
-
25
- # remove is
26
- word_array.shift
27
-
28
- value = DSON::Value.handle_next(options)
29
- parent_hash[key] = value
30
-
31
- so_parse(options)
32
- end
33
-
34
- POTENTIAL_PUNCTUATION = %w(, . ! ?)
35
-
36
- attr_reader :value
37
-
38
- def initialize(value)
39
- @value = value
40
- end
41
-
42
- def such_serialize_wow
43
- strings = value.keys.map do |key|
44
- key_str = StringValue.new(key).such_serialize_wow
45
- value_str = Value.new(value[key]).such_serialize_wow
46
-
47
- %Q(#{key_str} is #{value_str})
48
- end
49
- 'such ' + reduce(strings, POTENTIAL_PUNCTUATION) + 'wow'
50
- end
51
-
52
- def self.parse_pair(string, acc_hash)
53
- results = string.scan(/"(.*)" is (.*)/)
54
- acc_hash[results[0][0]] = DSON::Value.so_parse(results[0][1])
55
- acc_hash
56
- end
57
- end
58
- end
59
- end
1
+ # -*- encoding : utf-8 -*-
2
+ require 'DSON/value'
3
+
4
+ module DSON
5
+ module Value
6
+ class HashValue
7
+ include Value
8
+
9
+ def self.so_parse(options)
10
+ word_array = options[:word_array]
11
+ parent_hash = options[:parent_hash]
12
+ return parent_hash if word_array.empty?
13
+
14
+ if word_array[0] == 'wow'
15
+ word_array.shift
16
+ return parent_hash
17
+ end
18
+
19
+ # The next value will be a key
20
+ key = word_array.shift[1..-2]
21
+
22
+ # remove is
23
+ word_array.shift
24
+
25
+ value = DSON::Value.handle_next(options)
26
+ parent_hash[key] = value
27
+
28
+ so_parse(options)
29
+ end
30
+
31
+ POTENTIAL_PUNCTUATION = %w(, . ! ?)
32
+
33
+ attr_reader :value
34
+
35
+ def initialize(value)
36
+ @value = value
37
+ end
38
+
39
+ def such_serialize_wow
40
+ strings = value.keys.map do |key|
41
+ key_str = StringValue.new(key).such_serialize_wow
42
+ value_str = Value.new(value[key]).such_serialize_wow
43
+
44
+ %Q(#{key_str} is #{value_str})
45
+ end
46
+ 'such ' + reduce(strings, POTENTIAL_PUNCTUATION) + 'wow'
47
+ end
48
+
49
+ def self.parse_pair(string, acc_hash)
50
+ results = string.scan(/"(.*)" is (.*)/)
51
+ acc_hash[results[0][0]] = DSON::Value.so_parse(results[0][1])
52
+ acc_hash
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,21 +1,21 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'DSON/value'
3
-
4
- require 'singleton'
5
-
6
- module DSON
7
- module Value
8
- class NilValue
9
- include Value
10
- include Singleton
11
-
12
- def self.so_parse
13
- nil
14
- end
15
-
16
- def such_serialize_wow
17
- 'empty'
18
- end
19
- end
20
- end
21
- end
1
+ # -*- encoding : utf-8 -*-
2
+ require 'DSON/value'
3
+
4
+ require 'singleton'
5
+
6
+ module DSON
7
+ module Value
8
+ class NilValue
9
+ include Value
10
+ include Singleton
11
+
12
+ def self.so_parse
13
+ nil
14
+ end
15
+
16
+ def such_serialize_wow
17
+ 'empty'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,20 +1,40 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'DSON/value'
3
-
4
- module DSON
5
- module Value
6
- class NumericValue
7
- include Value
8
-
9
- attr_reader :value
10
-
11
- def initialize(value)
12
- @value = value
13
- end
14
-
15
- def such_serialize_wow
16
- value
17
- end
18
- end
19
- end
20
- end
1
+ # -*- encoding : utf-8 -*-
2
+ require 'DSON/value'
3
+
4
+ module DSON
5
+ module Value
6
+ class NumericValue
7
+ include Value
8
+
9
+ attr_reader :value
10
+
11
+ def initialize(value)
12
+ @value = value
13
+ end
14
+
15
+ def self.so_parse(value)
16
+ if value.include?('very') || value.include?('VERY')
17
+ parts = value.downcase.split('very')
18
+ octal_string_to_numeric(parts[0]) * 8 ** octal_string_to_numeric(parts[1])
19
+ else
20
+ octal_string_to_numeric(value)
21
+ end
22
+ end
23
+
24
+ def such_serialize_wow
25
+ value.b(8).to_s
26
+ end
27
+
28
+ private
29
+
30
+ def self.octal_string_to_numeric(value)
31
+ value = value.b(8)
32
+ if value.kind_of?(Radix::Float)
33
+ value.to_f
34
+ else
35
+ value.to_i
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,37 +1,37 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'DSON/value'
3
-
4
- module DSON
5
- module Value
6
- class ObjectValue
7
- include Value
8
-
9
- attr_reader :value
10
-
11
- def initialize(value)
12
- @value = value
13
- end
14
-
15
- def such_serialize_wow
16
- # Construct a hash of the instance variables
17
- object_hash = Hash[
18
- value.instance_variables.map do |variable|
19
- [
20
- remove_at_from_attribute_name(variable),
21
- value.instance_variable_get(variable)
22
- ]
23
- end
24
- ]
25
-
26
- value = DSON::Value.new(object_hash)
27
- value.such_serialize_wow
28
- end
29
-
30
- private
31
-
32
- def remove_at_from_attribute_name(attribute_name)
33
- attribute_name[1..-1]
34
- end
35
- end
36
- end
37
- end
1
+ # -*- encoding : utf-8 -*-
2
+ require 'DSON/value'
3
+
4
+ module DSON
5
+ module Value
6
+ class ObjectValue
7
+ include Value
8
+
9
+ attr_reader :value
10
+
11
+ def initialize(value)
12
+ @value = value
13
+ end
14
+
15
+ def such_serialize_wow
16
+ # Construct a hash of the instance variables
17
+ object_hash = Hash[
18
+ value.instance_variables.map do |variable|
19
+ [
20
+ remove_at_from_attribute_name(variable),
21
+ value.instance_variable_get(variable)
22
+ ]
23
+ end
24
+ ]
25
+
26
+ value = DSON::Value.new(object_hash)
27
+ value.such_serialize_wow
28
+ end
29
+
30
+ private
31
+
32
+ def remove_at_from_attribute_name(attribute_name)
33
+ attribute_name[1..-1]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,25 +1,26 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'DSON/value'
3
-
4
- module DSON
5
- module Value
6
- class StringValue
7
- include Value
8
-
9
- attr_reader :value
10
-
11
- def self.so_parse(options)
12
- numeric_identifier = options[:first_word]
13
- options[:string_hash][numeric_identifier.to_i]
14
- end
15
-
16
- def initialize(value)
17
- @value = value
18
- end
19
-
20
- def such_serialize_wow
21
- "\"#{value}\""
22
- end
23
- end
24
- end
25
- end
1
+ # -*- encoding : utf-8 -*-
2
+ require 'DSON/value'
3
+
4
+ module DSON
5
+ module Value
6
+ class StringValue
7
+ include Value
8
+
9
+ attr_reader :value
10
+
11
+ def self.so_parse(value)
12
+ start_index = value.index('"') + 1
13
+ end_index = value.rindex('"') - 1
14
+ value[start_index..end_index]
15
+ end
16
+
17
+ def initialize(value)
18
+ @value = value
19
+ end
20
+
21
+ def such_serialize_wow
22
+ "\"#{value}\""
23
+ end
24
+ end
25
+ end
26
+ end