Skip to content

Commit

Permalink
Introduce meaningful constant name
Browse files Browse the repository at this point in the history
Replace raw regex with a named constant that conveys the intended
expression match.
  • Loading branch information
harlow committed Dec 21, 2013
1 parent c1c3106 commit 215c808
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/twitter/rest/request/multipart_with_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module REST
module Request
class MultipartWithFile < Faraday::Middleware
CONTENT_TYPE = 'Content-Type'
GIF_REGEX = /\.gif$/i
JPEG_REGEX = /\.jpe?g/i
PNG_REGEX = /\.png$/i

def call(env)
env[:body].each do |key, value|
Expand All @@ -19,11 +22,11 @@ def call(env)

def mime_type(path)
case path
when /\.jpe?g/i
'image/jpeg'
when /\.gif$/i
when GIF_REGEX
'image/gif'
when /\.png$/i
when JPEG_REGEX
'image/jpeg'
when PNG_REGEX
'image/png'
else
'application/octet-stream'
Expand Down
4 changes: 3 additions & 1 deletion lib/twitter/rest/response/parse_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ module Twitter
module REST
module Response
class ParseJson < Faraday::Response::Middleware
WHITESPACE_REGEX = /\A^\s*$\z/

def parse(body)
case body
when /\A^\s*$\z/, nil
when WHITESPACE_REGEX, nil
nil
else
JSON.parse(body, :symbolize_names => true)
Expand Down

0 comments on commit 215c808

Please sign in to comment.