Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String Manipulation and Comparison Operations #341

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/http/content_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def parse(str)

# :nodoc:
def mime_type(str)
md = str.to_s.match MIME_TYPE_RE
md && md[1].to_s.strip.downcase
m = str.to_s[MIME_TYPE_RE, 1]
m && m.strip.downcase
end

# :nodoc:
def charset(str)
md = str.to_s.match CHARSET_RE
md && md[1].to_s.strip.gsub(/^"|"$/, "")
m = str.to_s[CHARSET_RE, 1]
m && m.strip.delete('"')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/http/response/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def coerce(object)
# @param [#to_s] str
# @return [Symbol]
def symbolize(str)
str.to_s.downcase.tr("-", " ").gsub(/[^a-z ]/, "").gsub(/\s+/, "_").to_sym
str.to_s.downcase.tr("- ", "_").delete("^a-z_").to_sym
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[1] pry(main)> "Bad  request".downcase.tr("- ", "_").delete("^a-z_").to_sym
=> :bad__request
[2] pry(main)> "Bad  request".downcase.tr("-", " ").gsub(/[^a-z ]/, "").gsub(/\s+/, "_").to_sym
=> :bad_request

end
end

Expand Down