better_struct 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 006098f63de80140f1925efccb3c7ee6fe3c6b8b
4
- data.tar.gz: edcd040ce1895c46e517a7cbcc15054c2097fa32
3
+ metadata.gz: 49ee1e52bc87787a1b4121fee32ea09ce4f0a18f
4
+ data.tar.gz: 853cb5b74e74587f456235c4f8096635e77e8962
5
5
  SHA512:
6
- metadata.gz: e23162469cfd0a28d775c3ca523792e5752d121b77f7661b38c9f4d0763e27daf83f3bbbddc46a81c23c862862deb0791f6f3f560748adc31449d015bea3ee60
7
- data.tar.gz: c989dfbee079dc0ebc22ca59691cb9c4f86eb6afdb24bb3c71136afd88e2314f0cc9463b423928f2924338e778e50adfaa65d9ad621e7670edbaff51671a7542
6
+ metadata.gz: 1d1a0c746df874e3a5c84768a07a0b239d1328549599cf444fd8b286a348cbccca24738c4bfb9f7e326d386683adb3d2fa19176277d5c0dd2c4ae30b17743d5e
7
+ data.tar.gz: 8287fbc543dbafd3ebf7419951519b96b4ecd8c3da7f8d490100a03422dfc47fe952738531eba98b6d3d5721f7f68efe1292bc1c0483e3d48adff6172da49e25
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "activesupport", "~> 3.2"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.7"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
23
25
  spec.add_development_dependency "minitest", "~> 5.5"
@@ -1,3 +1,3 @@
1
1
  class BetterStruct
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/better_struct.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "better_struct/version"
2
2
  require "forwardable"
3
+ require "active_support/inflector"
3
4
 
4
5
  class BetterStruct
5
6
  extend Forwardable
@@ -12,7 +13,7 @@ class BetterStruct
12
13
  @defined_methods = {}
13
14
 
14
15
  if value && value.respond_to?(:each_pair)
15
- value.each_pair { |key, value| @defined_methods[underscore(key.to_s)] = value }
16
+ value.each_pair { |key, value| @defined_methods[methodize(key.to_s)] = value }
16
17
  end
17
18
  end
18
19
 
@@ -26,6 +27,10 @@ class BetterStruct
26
27
 
27
28
  private
28
29
 
30
+ def methodize(string)
31
+ ActiveSupport::Inflector.parameterize(ActiveSupport::Inflector.underscore(string), "_")
32
+ end
33
+
29
34
  def wrap(value)
30
35
  value.is_a?(self.class) ? self : self.class.new(value)
31
36
  end
@@ -39,17 +44,6 @@ private
39
44
  end
40
45
  end
41
46
 
42
- def underscore(word)
43
- return word.to_s if word.to_s =~ /\A[a-z0-9_]+\z/
44
-
45
- word = word.to_s.gsub(/\W+/, '_')
46
- word.gsub!(/\A[_]+|[_]+\z/, '')
47
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
48
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
49
- word.downcase!
50
- word
51
- end
52
-
53
47
  def method_missing(*args, &block)
54
48
  method_name = args.first.to_s
55
49
 
@@ -63,4 +63,8 @@ class BetterStructTest < Minitest::Test
63
63
  def test_underscoring_methods
64
64
  assert BetterStruct.new({ "Word (With-Space)" => 1 }).word_with_space.value == 1
65
65
  end
66
+
67
+ def test_transliteration
68
+ assert BetterStruct.new({ "Título" => 1 }).titulo.value == 1
69
+ end
66
70
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-19 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement