ribbon 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/LICENSE.GPLv3 +14 -0
- data/README.markdown +9 -0
- data/Rakefile +3 -0
- data/lib/ribbon/object.rb +71 -0
- data/lib/ribbon/version.rb +31 -0
- data/lib/ribbon.rb +2 -0
- data/ribbon.gemspec +21 -0
- metadata +65 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.lock
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create 1.9.3@ribbon
|
data/Gemfile
ADDED
data/LICENSE.GPLv3
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright © 2011 Matheus Afonso Martins Moreira
|
2
|
+
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
4
|
+
it under the terms of the GNU General Public License as published by
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
6
|
+
(at your option) any later version.
|
7
|
+
|
8
|
+
This program is distributed in the hope that it will be useful,
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
GNU General Public License for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU General Public License
|
14
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/README.markdown
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module Ribbon
|
2
|
+
|
3
|
+
# Contains a hash whose keys that are symbols or strings can be accessed via
|
4
|
+
# method calls. This is done via <tt>method_missing</tt>.
|
5
|
+
#
|
6
|
+
# In order to make room for as many method names as possible, Ribbon::Object
|
7
|
+
# inherits from BasicObject.
|
8
|
+
class Object < BasicObject
|
9
|
+
|
10
|
+
# The internal Hash.
|
11
|
+
def __hash__
|
12
|
+
@hash ||= {}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Merges the internal hash with the given one.
|
16
|
+
def initialize(hash = {}, &block)
|
17
|
+
__hash__.merge! hash, &block
|
18
|
+
end
|
19
|
+
|
20
|
+
# Gets a value by key.
|
21
|
+
def [](key)
|
22
|
+
__hash__[key]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Sets a value by key.
|
26
|
+
def []=(key, value)
|
27
|
+
__hash__[key] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
# Handles the following cases:
|
31
|
+
#
|
32
|
+
# options.method = value => rbon[method] = value
|
33
|
+
# options.method! value => rbon[method] = value
|
34
|
+
# options.method? => rbon[method] ? true : false
|
35
|
+
# options.method => rbon[method]
|
36
|
+
def method_missing(method, *args, &block)
|
37
|
+
m = method.to_s.strip.chop.strip.to_sym
|
38
|
+
case method.to_s[-1]
|
39
|
+
when '=', '!'
|
40
|
+
self[m] = args.first
|
41
|
+
when '?'
|
42
|
+
self[m] ? true : false
|
43
|
+
else
|
44
|
+
self[method] = if __hash__.has_key? method
|
45
|
+
::Ribbon::Object.convert self[method]
|
46
|
+
else
|
47
|
+
::Ribbon::Object.new
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
values = __hash__.map { |k, v| "#{k}:#{v}" }
|
54
|
+
"<Ribbon #{values.join}>"
|
55
|
+
end
|
56
|
+
|
57
|
+
alias :inspect :to_s
|
58
|
+
|
59
|
+
# If <tt>object</tt> is a Hash, converts it to a Ribbon::Object. If it is
|
60
|
+
# an Array, converts any hashes inside.
|
61
|
+
def self.convert(object)
|
62
|
+
case object
|
63
|
+
when ::Hash then self.new object
|
64
|
+
when ::Array then object.map { |element| convert element }
|
65
|
+
else object
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Ribbon
|
2
|
+
|
3
|
+
# Ribbon's version.
|
4
|
+
module Version
|
5
|
+
|
6
|
+
# Major version.
|
7
|
+
#
|
8
|
+
# Increments denote backward-incompatible changes and additions.
|
9
|
+
MAJOR = 0
|
10
|
+
|
11
|
+
# Minor version.
|
12
|
+
#
|
13
|
+
# Increments denote backward-compatible changes and additions.
|
14
|
+
MINOR = 0
|
15
|
+
|
16
|
+
# Patch version.
|
17
|
+
#
|
18
|
+
# Increments denote changes in implementation.
|
19
|
+
PATCH = 1
|
20
|
+
|
21
|
+
# Build version.
|
22
|
+
#
|
23
|
+
# Used for pre-release versions.
|
24
|
+
BUILD = nil
|
25
|
+
|
26
|
+
# Complete version string, which is every individual version number joined
|
27
|
+
# by a dot (<tt>'.'</tt>), in descending order of prescedence.
|
28
|
+
STRING = [ MAJOR, MINOR, PATCH, BUILD ].compact.join '.'
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/ribbon.rb
ADDED
data/ribbon.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env gem build
|
2
|
+
# encoding: utf-8
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
|
5
|
+
require 'ribbon/version'
|
6
|
+
|
7
|
+
Gem::Specification.new('ribbon') do |gem|
|
8
|
+
|
9
|
+
gem.version = Ribbon::Version::STRING
|
10
|
+
gem.summary = 'Ruby Object Notation.'
|
11
|
+
gem.description = "#{gem.summary} Inspired by JSON and OpenStruct."
|
12
|
+
gem.homepage = 'https://github.com/matheusmoreira/ribbon'
|
13
|
+
|
14
|
+
gem.author = 'Matheus Afonso Martins Moreira'
|
15
|
+
gem.email = 'matheus.a.m.moreira@gmail.com'
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split "\n"
|
18
|
+
|
19
|
+
gem.add_development_dependency 'rookie'
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ribbon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matheus Afonso Martins Moreira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rookie
|
16
|
+
requirement: &17594200 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *17594200
|
25
|
+
description: Ruby Object Notation. Inspired by JSON and OpenStruct.
|
26
|
+
email: matheus.a.m.moreira@gmail.com
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- .rvmrc
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE.GPLv3
|
35
|
+
- README.markdown
|
36
|
+
- Rakefile
|
37
|
+
- lib/ribbon.rb
|
38
|
+
- lib/ribbon/object.rb
|
39
|
+
- lib/ribbon/version.rb
|
40
|
+
- ribbon.gemspec
|
41
|
+
homepage: https://github.com/matheusmoreira/ribbon
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.8.10
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Ruby Object Notation.
|
65
|
+
test_files: []
|