space_object 0.1.1

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NGZkZTdlNzAxMjA1YjIxOTA5YTk2NGY0MjY1ZjUzOWMxYTg0N2EyNA==
5
+ data.tar.gz: !binary |-
6
+ ZjBmZWI0OGQxZjRiMzEzNjNjMzliNDRjOTE4Mzk5NTAzNmYwOGU3YQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTc1ZmY5ZjY2MjcyOGQ5N2IwOWNkMzg4Zjc3OTU5ZDYwZDY1NTJkMjk3MDE4
10
+ MGIzNmQ0NGNiMmNlYzAxMGU0MmYwN2E1ZGU4MjFjZWFiZjFiMTY3NzNmMjMw
11
+ OTIzMmNhY2JkNjc3YjRhOThmZDNkNmJkY2JlMTAzNmUwZWUxNDY=
12
+ data.tar.gz: !binary |-
13
+ MWEwM2E4YmJiM2I1MzZhNjE3MWY0ZjhiNThkMjZlNzBkZjgyMjZkZTg5MDk0
14
+ NjViN2JhMjU2NzU3MDczOGFlZmU2N2RjODk3NzU3MGM1MWI2NTVmNjc2MTg3
15
+ NWI2NWU2NGViMjBlYTNmMmE2ZDMzNDMxY2FiYzdhMzA3OWIwMzU=
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ README.rdoc
3
+ ChangeLog.rdoc
4
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ html/
2
+ pkg/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/ChangeLog.rdoc ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 / 2013-11-03
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ space_object (0.0.1)
5
+ activesupport (~> 4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.0.1)
11
+ i18n (~> 0.6, >= 0.6.4)
12
+ minitest (~> 4.2)
13
+ multi_json (~> 1.3)
14
+ thread_safe (~> 0.1)
15
+ tzinfo (~> 0.3.37)
16
+ atomic (1.1.14)
17
+ diff-lcs (1.2.4)
18
+ i18n (0.6.5)
19
+ json (1.8.1)
20
+ minitest (4.7.5)
21
+ multi_json (1.8.2)
22
+ rdoc (3.12.2)
23
+ json (~> 1.4)
24
+ rspec (2.14.1)
25
+ rspec-core (~> 2.14.0)
26
+ rspec-expectations (~> 2.14.0)
27
+ rspec-mocks (~> 2.14.0)
28
+ rspec-core (2.14.7)
29
+ rspec-expectations (2.14.3)
30
+ diff-lcs (>= 1.1.3, < 2.0)
31
+ rspec-mocks (2.14.4)
32
+ rubygems-tasks (0.2.4)
33
+ thread_safe (0.1.3)
34
+ atomic
35
+ tzinfo (0.3.38)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ rdoc (~> 3.0)
42
+ rspec (~> 2.4)
43
+ rubygems-tasks (~> 0.2)
44
+ space_object!
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Robert Fruchtman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = space_object
2
+
3
+ * {Homepage}[https://github.com/fruchtose/space_object#readme]
4
+ * {Issues}[https://github.com/fruchtose/space_object/issues]
5
+ * {Documentation}[http://rubydoc.info/gems/space_object/frames]
6
+ * {Email}[mailto:rfruchtose at gmail.com]
7
+
8
+ == Description
9
+
10
+ TODO: Description
11
+
12
+ == Features
13
+
14
+ == Examples
15
+
16
+ require 'space_object'
17
+
18
+ == Requirements
19
+
20
+ == Install
21
+
22
+ $ gem install space_object
23
+
24
+ == Copyright
25
+
26
+ Copyright (c) 2013 Robert Fruchtman
27
+
28
+ See LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ begin
7
+ gem 'rubygems-tasks', '~> 0.2'
8
+ require 'rubygems/tasks'
9
+
10
+ Gem::Tasks.new
11
+ rescue LoadError => e
12
+ warn e.message
13
+ warn "Run `gem install rubygems-tasks` to install Gem::Tasks."
14
+ end
15
+
16
+ begin
17
+ gem 'rdoc', '~> 3.0'
18
+ require 'rdoc/task'
19
+
20
+ RDoc::Task.new do |rdoc|
21
+ rdoc.title = "space_object"
22
+ end
23
+ rescue LoadError => e
24
+ warn e.message
25
+ warn "Run `gem install rdoc` to install 'rdoc/task'."
26
+ end
27
+ task :doc => :rdoc
28
+
29
+ begin
30
+ gem 'rspec', '~> 2.4'
31
+ require 'rspec/core/rake_task'
32
+
33
+ RSpec::Core::RakeTask.new
34
+ rescue LoadError => e
35
+ task :spec do
36
+ abort "Please run `gem install rspec` to install RSpec."
37
+ end
38
+ end
39
+
40
+ task :test => :spec
41
+ task :default => :spec
@@ -0,0 +1,6 @@
1
+ require 'active_support/ordered_hash'
2
+
3
+ module SpaceObject
4
+ class Base < ActiveSupport::OrderedHash
5
+ end
6
+ end
@@ -0,0 +1,36 @@
1
+ module SpaceObject
2
+ class Parser
3
+ DELIMITER = /\n(?! )/
4
+ LEAF = /^([^ ]+) /
5
+ KEY_LINE = /^([^ ]+)(\n|$)/
6
+ NEST_SPACING = /\n /
7
+
8
+ def initialize(document)
9
+ @document = (document || '')
10
+ end
11
+
12
+ def parse
13
+ prepare_string
14
+ parse_string(@document)
15
+ end
16
+
17
+ private
18
+ def prepare_string
19
+ @document = @document.strip.gsub(/(\r\n|\n\r|\n\n+)/, "\n")
20
+ end
21
+
22
+ def parse_string(str)
23
+ str.split(DELIMITER).inject(Base.new) do |obj, space|
24
+ key, value = if matches = KEY_LINE.match(space)
25
+ offset = matches[1].length
26
+ [matches[1], parse_string(space[offset..-1].gsub(NEST_SPACING, "\n"))]
27
+ elsif matches = LEAF.match(space)
28
+ offset = matches[1].length + 1
29
+ [matches[1], space[offset..-1].gsub(NEST_SPACING, "\n")]
30
+ end
31
+ key and obj[key] = value
32
+ obj
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ module SpaceObject
2
+ # space_object version
3
+ VERSION = "0.1.1"
4
+ end
@@ -0,0 +1,11 @@
1
+ require 'space_object/version'
2
+ require 'space_object/base'
3
+ require 'space_object/parser'
4
+
5
+ module SpaceObject
6
+ class << self
7
+ def parse(document)
8
+ Parser.new(document).parse
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/space_object/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "space_object"
7
+ gem.version = SpaceObject::VERSION
8
+ gem.summary = %q{A lightweight language for objects}
9
+ gem.license = "MIT"
10
+ gem.authors = ["Robert Fruchtman"]
11
+ gem.email = "rfruchtose@gmail.com"
12
+ gem.homepage = "https://github.com/fruchtose/space_object#readme"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^spec/})
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_development_dependency 'rdoc', '~> 3.0'
20
+ gem.add_development_dependency 'rspec', '~> 2.4'
21
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
22
+ gem.add_runtime_dependency 'activesupport', '~> 4.0'
23
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpaceObject::Base do
4
+ it 'is an ActiveSupport::OrderedHash' do
5
+ expect(subject).to be_an(ActiveSupport::OrderedHash)
6
+ end
7
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpaceObject::Parser do
4
+ describe '#parse' do
5
+ shared_examples_for 'correctness' do |document, expected|
6
+ subject { SpaceObject::Parser.new(document) }
7
+ it 'parses the string correctly' do
8
+ result = subject.parse
9
+ expect(result).to eql(expected)
10
+ end
11
+ end
12
+
13
+ context 'when given nil' do
14
+ it_has_behavior 'correctness', nil, SpaceObject::Base.new
15
+ end
16
+
17
+ context 'when given an empty string' do
18
+ it_has_behavior 'correctness', '', SpaceObject::Base.new
19
+ end
20
+
21
+ context 'when given a key-value pair' do
22
+ it_has_behavior 'correctness', 'key value', SpaceObject::Base.try_convert({'key' => 'value'})
23
+ end
24
+
25
+ context 'when given multiple key-value pairs' do
26
+ it_has_behavior 'correctness', "1 2\na b", SpaceObject::Base.try_convert({'1' => '2', 'a' => 'b'})
27
+ end
28
+
29
+ context 'when given a nested space' do
30
+ document = "foo\n" +
31
+ " bar\n" +
32
+ " baz foobar"
33
+ expected = SpaceObject::Base.try_convert({
34
+ 'foo' => SpaceObject::Base.try_convert({
35
+ 'bar' => SpaceObject::Base.new,
36
+ 'baz' => 'foobar'
37
+ })
38
+ })
39
+ it_has_behavior 'correctness', document, expected
40
+ end
41
+
42
+ it 'produces a SpaceObject::Base object ordered according to input' do
43
+ ('a'..'d').to_a.permutation.each do |permutation|
44
+ document = permutation.join("\n")
45
+ object = SpaceObject::Parser.new(document).parse
46
+ expect(object.keys).to eq(permutation)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe SpaceObject do
4
+ it "should have a VERSION constant" do
5
+ expect(subject.const_get('VERSION')).not_to be_empty
6
+ end
7
+
8
+ describe "::parse" do
9
+ let(:test_document) { 'foo bar' }
10
+
11
+ before(:each) {
12
+ @instance = SpaceObject::Parser.new(test_document)
13
+ SpaceObject::Parser.stub(:new).and_return(@instance)
14
+ }
15
+
16
+ it "creates a new SpaceObject::Parser" do
17
+ SpaceObject.parse(test_document) and expect(SpaceObject::Parser).to have_received(:new).with(test_document)
18
+ end
19
+
20
+ it "calls SpaceObject::Parser#parse" do
21
+ @instance.stub(:parse)
22
+ SpaceObject.parse(test_document) and expect(@instance).to have_received(:parse)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'space_object'
5
+
6
+ RSpec.configure do |c|
7
+ c.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
8
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: space_object
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert Fruchtman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubygems-tasks
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ description:
70
+ email: rfruchtose@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - .document
76
+ - .gitignore
77
+ - .rspec
78
+ - ChangeLog.rdoc
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - lib/space_object.rb
85
+ - lib/space_object/base.rb
86
+ - lib/space_object/parser.rb
87
+ - lib/space_object/version.rb
88
+ - space_object.gemspec
89
+ - spec/space_object/base_spec.rb
90
+ - spec/space_object/parser_spec.rb
91
+ - spec/space_object_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: https://github.com/fruchtose/space_object#readme
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.0.7
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A lightweight language for objects
117
+ test_files:
118
+ - spec/space_object/base_spec.rb
119
+ - spec/space_object/parser_spec.rb
120
+ - spec/space_object_spec.rb
121
+ - spec/spec_helper.rb