You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/10/19 15:44:09 UTC

[PATCH core 3/4] Core: Improved camelize method to upcase first letter in string

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/core_ext/string.rb |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/deltacloud/core_ext/string.rb
index 1cd79a0..42d5677 100644
--- a/server/lib/deltacloud/core_ext/string.rb
+++ b/server/lib/deltacloud/core_ext/string.rb
@@ -52,6 +52,6 @@ class String
 
 
   def camelize
-    gsub(/_[a-z]/) { |match| match[1].chr.upcase }
+    split('_').map { |w| w.capitalize }.join
   end
 end
-- 
1.7.4.4


Re: [PATCH core 3/4] Core: Improved camelize method to upcase first letter in string

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-10-19 at 15:44 +0200, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
>  server/lib/deltacloud/core_ext/string.rb |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

ACK



Re: [PATCH core 3/4] Core: Improved camelize method to upcase first letter in string

Posted by Michal Fojtik <mf...@redhat.com>.
On Oct 20, 2011, at 3:31 AM, Tong Li wrote:

> The changes actually break things. for a string like "machine_images", what is needed is actually "machineImages", not MachineImages, so the method does not do what it needs to. The original method does. I think that this patch needs to be reverted. The strings are actually needed in the cloudEntryPoint response. In other places, there is a need for MachineImage, but never the string MachineImages.

This is not really what .camelize method should do. However in ActiveSupport there is an option (:lower)
for this so I'll update my code to support this option as well:

class String

  def camelize(lowercase_first_letter=nil)
    s = split('_').map { |w| w.capitalize }.join
    lowercase_first_letter ? s.uncapitalize : s
  end

  def uncapitalize 
    self[0, 1].downcase + self[1..-1]
  end
end
 -- Michal

> 
> Thanks.
> 
> Tong Li
> Emerging Technologies & Standards
> B062/K317
> litong01@us.ibm.com
> 
> mfojtik---10/19/2011 09:55:03 AM---From: Michal Fojtik <mf...@redhat.com> Signed-off-by: Michal fojtik <mf...@redhat.com>
> 
> From:	mfojtik@redhat.com
> To:	deltacloud-dev@incubator.apache.org
> Date:	10/19/2011 09:55 AM
> Subject:	[PATCH core 3/4] Core: Improved camelize method to upcase first letter in string
> 
> 
> 
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
> server/lib/deltacloud/core_ext/string.rb |    2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/deltacloud/core_ext/string.rb
> index 1cd79a0..42d5677 100644
> --- a/server/lib/deltacloud/core_ext/string.rb
> +++ b/server/lib/deltacloud/core_ext/string.rb
> @@ -52,6 +52,6 @@ class String
> 
> 
>   def camelize
> -    gsub(/_[a-z]/) { |match| match[1].chr.upcase }
> +    split('_').map { |w| w.capitalize }.join
>   end
> end
> -- 
> 1.7.4.4
> 
> 

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org


Re: [PATCH core 3/4] Core: Improved camelize method to upcase first letter in string

Posted by Tong Li <li...@us.ibm.com>.
The changes actually break things. for a string like  "machine_images",
what is needed is actually "machineImages", not MachineImages, so the
method does not do what it needs to. The original method does. I think that
this patch needs to be reverted. The strings are actually needed in the
cloudEntryPoint response. In other places, there is a need for
MachineImage, but never the string MachineImages.

Thanks.

Tong Li
Emerging Technologies & Standards
B062/K317
litong01@us.ibm.com



From:	mfojtik@redhat.com
To:	deltacloud-dev@incubator.apache.org
Date:	10/19/2011 09:55 AM
Subject:	[PATCH core 3/4] Core: Improved camelize method to upcase first
            letter in string



From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/core_ext/string.rb |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/core_ext/string.rb
b/server/lib/deltacloud/core_ext/string.rb
index 1cd79a0..42d5677 100644
--- a/server/lib/deltacloud/core_ext/string.rb
+++ b/server/lib/deltacloud/core_ext/string.rb
@@ -52,6 +52,6 @@ class String


   def camelize
-    gsub(/_[a-z]/) { |match| match[1].chr.upcase }
+    split('_').map { |w| w.capitalize }.join
   end
 end
--
1.7.4.4