Permalink
Browse files

Introduce meaningful constant name

Replace raw regex with a named constant that conveys the intended
expression match.
  • Loading branch information...
1 parent c1c3106 commit 215c80890d702535de83d8f849885a95ec153920 @harlow harlow committed Dec 18, 2013
Showing with 10 additions and 5 deletions.
  1. +7 −4 lib/twitter/rest/request/multipart_with_file.rb
  2. +3 −1 lib/twitter/rest/response/parse_json.rb
@@ -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|
@@ -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'
@@ -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)

0 comments on commit 215c808

Please sign in to comment.