better_struct 0.1.2 → 0.1.3

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: 7412170d20c983591a234c44890b2193d6de770b
4
- data.tar.gz: 33be1a359fde94fc3a4e12456f1fd2bb334a0246
3
+ metadata.gz: 006098f63de80140f1925efccb3c7ee6fe3c6b8b
4
+ data.tar.gz: edcd040ce1895c46e517a7cbcc15054c2097fa32
5
5
  SHA512:
6
- metadata.gz: 0a5c7bf02dad0688bdd984d6f14561ecc92d032d50f8c56176dfad561ac6fb4fd01f5d42b3041a2845700a84a3839a520b379cef8ec0bad4a79fb92d5791149f
7
- data.tar.gz: 540cac12c69851eafbd2d43070c0df506f763a3a2a2fa9691cc21a8a2f0ec02ede6c264dcad5321fb73e8a60ef0376438b2622bd4a01c552db1d60b87c43e02a
6
+ metadata.gz: e23162469cfd0a28d775c3ca523792e5752d121b77f7661b38c9f4d0763e27daf83f3bbbddc46a81c23c862862deb0791f6f3f560748adc31449d015bea3ee60
7
+ data.tar.gz: c989dfbee079dc0ebc22ca59691cb9c4f86eb6afdb24bb3c71136afd88e2314f0cc9463b423928f2924338e778e50adfaa65d9ad621e7670edbaff51671a7542
data/lib/better_struct.rb CHANGED
@@ -39,13 +39,13 @@ private
39
39
  end
40
40
  end
41
41
 
42
- def underscore(camel_cased_word)
43
- return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
42
+ def underscore(word)
43
+ return word.to_s if word.to_s =~ /\A[a-z0-9_]+\z/
44
44
 
45
- word = camel_cased_word.to_s.gsub(/::/, '/')
45
+ word = word.to_s.gsub(/\W+/, '_')
46
+ word.gsub!(/\A[_]+|[_]+\z/, '')
46
47
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
47
48
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
48
- word.tr!("- ", "_")
49
49
  word.downcase!
50
50
  word
51
51
  end
@@ -1,3 +1,3 @@
1
1
  class BetterStruct
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -61,6 +61,6 @@ class BetterStructTest < Minitest::Test
61
61
  end
62
62
 
63
63
  def test_underscoring_methods
64
- assert BetterStruct.new({ "Word With-Space" => 1 }).word_with_space.value == 1
64
+ assert BetterStruct.new({ "Word (With-Space)" => 1 }).word_with_space.value == 1
65
65
  end
66
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li