Skip to content

Commit

Permalink
rename snake_case method to to_snake_case; update specs; bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
zokioki committed Apr 3, 2016
1 parent b6c7ec0 commit 09c6f49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/fitbyte/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def format_scope(scope)
# Borrowing from Rails

def deep_keys_to_snake_case!(object)
deep_transform_keys!(object) { |key| snake_case(key) }
deep_transform_keys!(object) { |key| to_snake_case(key) }
end

def deep_symbolize_keys!(object)
Expand All @@ -44,7 +44,7 @@ def deep_transform_keys!(object, &block)
end
end

def snake_case(word)
def to_snake_case(word)
word = word.to_s.dup
return word.downcase if word.match(/\A[A-Z]+\z/)
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
Expand Down
2 changes: 1 addition & 1 deletion lib/fitbyte/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Fitbyte
VERSION = "0.3.0"
VERSION = "0.4.0"
REPO_URL = "https://github.com/zokioki/fitbyte"
end
12 changes: 12 additions & 0 deletions spec/client/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@
expect(client.deep_symbolize_keys! object).to eq({ keyOne: 1, keyTwo: { keyThree: 3, keyFour: 4 } })
end
end

describe "#to_snake_case" do
it "converts camelCased words to snake_case format" do
word = "imMrMeeseeksLookAtMe"
expect(client.to_snake_case word).to eq "im_mr_meeseeks_look_at_me"
end

it "properly recognizes series of capital letters as single word" do
word = "iThinkNASAIsCool"
expect(client.to_snake_case word).to eq "i_think_nasa_is_cool"
end
end
end

0 comments on commit 09c6f49

Please sign in to comment.