humanized 0.0.1.alpha

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.
@@ -0,0 +1,74 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the Affero GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
+ #
15
+ # (c) 2011 by Hannes Georg
16
+ #
17
+ require "delegate"
18
+ module Humanized
19
+
20
+ class Wrapper < Delegator
21
+
22
+ UNWRAPPED = [:object_id, :__send__ , :__id__ ,:method_missing , :respond_to?, :respond_to_missing? , :class, :instance_of?, :instance_eval, :instance_exec].freeze
23
+
24
+ unless RUBY_VERSION >= '1.9.0'
25
+ Object.new.methods.each do |meth|
26
+ unless UNWRAPPED.include? meth.to_sym
27
+ begin
28
+ undef_method meth
29
+ rescue NameError => e
30
+ warn e.to_s
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def __getobj__
37
+ @object
38
+ end
39
+
40
+ def __setobj__(obj)
41
+ @object = obj
42
+ end
43
+
44
+ def self.wrap(*args, &block)
45
+ a = args.flatten.map{|o|
46
+ self.new(o,&block)
47
+ }
48
+ return a.size == 1 ? a[0] : a
49
+ end
50
+
51
+ def initialize(object, __to_s__ = nil, &block)
52
+ self.__setobj__(object)
53
+ if block_given?
54
+ @block = block
55
+ elsif __to_s__.kind_of? String
56
+ @block = eval("lambda{ %{#{__to_s__}} }")
57
+ elsif __to_s__.kind_of? Array
58
+ @block = lambda{ __to_s__[0].to_s + to_s + __to_s__[1].to_s }
59
+ else
60
+ raise ArgumentError, "Wrapper.initialize expects a String or a block"
61
+ end
62
+ end
63
+
64
+ def to_s
65
+ if @block.arity == 1
66
+ return @block.call(@object)
67
+ else
68
+ return @object.instance_exec(&@block)
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,50 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the Affero GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
+ #
15
+ # (c) 2011 by Hannes Georg
16
+ #
17
+ module Humanized
18
+
19
+ module JsonSource
20
+
21
+ def read_json(file)
22
+
23
+ f = File.open(file)
24
+
25
+ js = JsonSource.translate(Yajl::Parser.new(:symbolize_keys => true).parse( f ))
26
+
27
+ f.close
28
+
29
+ return js
30
+ end
31
+
32
+ protected
33
+ def self.translate( o )
34
+ if o.kind_of? Hash
35
+ r = {}
36
+ o.each{|k,v| r[k] = translate(v) }
37
+ return r
38
+ elsif o.kind_of? Array
39
+ return o.map{|a| translate(a)}
40
+ elsif o.kind_of? String
41
+ if( o[0] == ?$ )
42
+ return o[1..-1].to_sym
43
+ end
44
+ end
45
+ return o
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the Affero GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
+ #
15
+ # (c) 2011 by Hannes Georg
16
+ #
17
+ require 'yaml'
18
+ module Humanized
19
+
20
+ module YamlSource
21
+
22
+ def read_yml(file)
23
+ YAML.load( File.open(file) )
24
+ end
25
+
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: humanized
3
+ version: !ruby/object:Gem::Version
4
+ hash: -1851332166
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - alpha
11
+ version: 0.0.1.alpha
12
+ platform: ruby
13
+ authors:
14
+ - HannesG
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-03-23 00:00:00 +01:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: facets
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ prerelease: false
34
+ type: :runtime
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ prerelease: false
48
+ type: :development
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: simplecov
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ prerelease: false
62
+ type: :development
63
+ requirement: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rake
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ prerelease: false
76
+ type: :development
77
+ requirement: *id004
78
+ description: Sick of writing culture dependent code? humanized could be for you.
79
+ email: hannes.georg@googlemail.com
80
+ executables: []
81
+
82
+ extensions: []
83
+
84
+ extra_rdoc_files: []
85
+
86
+ files:
87
+ - lib/more/humanized/yaml_source.rb
88
+ - lib/more/humanized/json_source.rb
89
+ - lib/humanized/humanizer.rb
90
+ - lib/humanized/compiler.rb
91
+ - lib/humanized/scope.rb
92
+ - lib/humanized/interpolation/date.rb
93
+ - lib/humanized/interpolation/german.rb
94
+ - lib/humanized/interpolation/number.rb
95
+ - lib/humanized/interpolation/english.rb
96
+ - lib/humanized/interpolation/kng.rb
97
+ - lib/humanized/interpolation/conjunctions.rb
98
+ - lib/humanized/core_ext/hash.rb
99
+ - lib/humanized/core_ext/date.rb
100
+ - lib/humanized/core_ext/array.rb
101
+ - lib/humanized/core_ext/time.rb
102
+ - lib/humanized/core_ext/object.rb
103
+ - lib/humanized/core_ext/module.rb
104
+ - lib/humanized/core_ext/string.rb
105
+ - lib/humanized/core_ext/nilclass.rb
106
+ - lib/humanized/core_ext/numeric.rb
107
+ - lib/humanized/core_ext/symbol.rb
108
+ - lib/humanized/source.rb
109
+ - lib/humanized/ref.rb
110
+ - lib/humanized/wrapper.rb
111
+ - lib/humanized.rb
112
+ has_rdoc: true
113
+ homepage: http://github.com/hannesg/humanized
114
+ licenses: []
115
+
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">"
134
+ - !ruby/object:Gem::Version
135
+ hash: 25
136
+ segments:
137
+ - 1
138
+ - 3
139
+ - 1
140
+ version: 1.3.1
141
+ requirements: []
142
+
143
+ rubyforge_project:
144
+ rubygems_version: 1.5.0
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: advanced i18n for ruby
148
+ test_files: []
149
+