Permalink
Browse files

Remove unnecessary method definitions

  • Loading branch information...
sferik committed Dec 31, 2013
1 parent 629ab5e commit 1304fb462e7e37196df4346beb24c21cd4343ba6
View
@@ -73,7 +73,7 @@ def display_uri_attr_reader
# @param key2 [Symbol]
def define_uri_method(key1, key2)
define_method(key1) do ||
- Addressable::URI.parse(@attrs[key2]) if @attrs[key2]
+ Addressable::URI.parse(@attrs[key2]) unless @attrs[key2].nil?
end
memoize(key1)
end
@@ -88,11 +88,11 @@ def define_attribute_method(key1, klass = nil, key2 = nil)
if klass.nil?
@attrs[key1]
else
- if @attrs[key1]
+ if @attrs[key1].nil?
+ NullObject.new
+ else
attrs = attrs_for_object(key1, key2)
Twitter.const_get(klass).new(attrs)
- else
- NullObject.new
end
end
end
View
@@ -9,7 +9,7 @@ module Creatable
#
# @return [Time]
def created_at
- Time.parse(@attrs[:created_at]) if @attrs[:created_at]
+ Time.parse(@attrs[:created_at]) unless @attrs[:created_at].nil?
end
memoize :created_at
View
@@ -26,7 +26,7 @@ def alias_method_sub(method, pattern, replacement)
# @param size [String, Symbol] The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina'
# @return [String]
def profile_banner_uri(size = :web)
- parse_encoded_uri(insecure_uri([@attrs[:profile_banner_url], size].join('/'))) if @attrs[:profile_banner_url]
+ parse_encoded_uri(insecure_uri([@attrs[:profile_banner_url], size].join('/'))) unless @attrs[:profile_banner_url].nil?
end
alias_method :profile_banner_url, :profile_banner_uri
@@ -35,7 +35,7 @@ def profile_banner_uri(size = :web)
# @param size [String, Symbol] The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina'
# @return [String]
def profile_banner_uri_https(size = :web)
- parse_encoded_uri([@attrs[:profile_banner_url], size].join('/')) if @attrs[:profile_banner_url]
+ parse_encoded_uri([@attrs[:profile_banner_url], size].join('/')) unless @attrs[:profile_banner_url].nil?
end
alias_method :profile_banner_url_https, :profile_banner_uri_https
@@ -51,7 +51,7 @@ def profile_banner_uri?
# @param size [String, Symbol] The size of the image. Must be one of: 'mini', 'normal', 'bigger' or 'original'
# @return [String]
def profile_image_uri(size = :normal)
- parse_encoded_uri(insecure_uri(profile_image_uri_https(size))) if @attrs[:profile_image_url_https]
+ parse_encoded_uri(insecure_uri(profile_image_uri_https(size))) unless @attrs[:profile_image_url_https].nil?
end
alias_method :profile_image_url, :profile_image_uri
@@ -66,7 +66,7 @@ def profile_image_uri_https(size = :normal)
# https://a0.twimg.com/profile_images/1759857427/image1326743606.png
# https://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png
# https://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png
- parse_encoded_uri(@attrs[:profile_image_url_https].sub(PROFILE_IMAGE_SUFFIX_REGEX, profile_image_suffix(size))) if @attrs[:profile_image_url_https]
+ parse_encoded_uri(@attrs[:profile_image_url_https].sub(PROFILE_IMAGE_SUFFIX_REGEX, profile_image_suffix(size))) unless @attrs[:profile_image_url_https].nil?
end
alias_method :profile_image_url_https, :profile_image_uri_https
@@ -38,7 +38,7 @@ def initialize(attrs = {})
#
# @return [Time]
def as_of
- Time.parse(@attrs[:as_of]) if @attrs[:as_of]
+ Time.parse(@attrs[:as_of]) unless @attrs[:as_of].nil?
end
memoize :as_of
View
@@ -6,13 +6,14 @@ module Twitter
class Tweet < Twitter::Identity
include Twitter::Creatable
include Twitter::Entities
- attr_reader :favorite_count, :favorited, :in_reply_to_screen_name,
- :in_reply_to_attrs_id, :in_reply_to_status_id,
- :in_reply_to_user_id, :lang, :retweet_count, :retweeted,
- :source, :text, :truncated
+ attr_reader :favorite_count, :favorited, :filter_level,
+ :in_reply_to_screen_name, :in_reply_to_attrs_id,
+ :in_reply_to_status_id, :in_reply_to_user_id, :lang,
+ :retweet_count, :retweeted, :source, :text, :truncated
alias_method :favorites_count, :favorite_count
alias_method :favoriters_count, :favorite_count
alias_method :in_reply_to_tweet_id, :in_reply_to_status_id
+ alias_method :reply?, :in_reply_to_status_id?
alias_method :retweeters_count, :retweet_count
object_attr_reader :GeoFactory, :geo
object_attr_reader :Metadata, :metadata
@@ -24,15 +25,10 @@ class Tweet < Twitter::Identity
alias_method :retweeted_tweet?, :retweeted_status?
object_attr_reader :User, :user, :status
- def filter_level
- @attrs[:filter_level] || 'none'
- end
- memoize :filter_level
-
- # @return [String]
# @note May be > 140 characters.
+ # @return [String]
def full_text
- if retweeted_status?
+ if retweet?
prefix = text[/\A(RT @[a-z0-9_]{1,20}: )/i, 1]
[prefix, retweeted_status.text].compact.join
else
@@ -41,15 +37,9 @@ def full_text
end
memoize :full_text
- # @return [Boolean]
- def reply?
- !!@attrs[:in_reply_to_status_id]
- end
- memoize :reply?
-
# @return [String] The URL to the tweet.
def uri
- Addressable::URI.parse("https://twitter.com/#{user.screen_name}/status/#{id}")
+ Addressable::URI.parse("https://twitter.com/#{user.screen_name}/status/#{id}") unless user.nil?
end
memoize :uri
alias_method :url, :uri
View
@@ -43,14 +43,14 @@ def description_uris
# @return [String] The URL to the user.
def uri
- Addressable::URI.parse("https://twitter.com/#{screen_name}")
+ Addressable::URI.parse("https://twitter.com/#{screen_name}") unless screen_name.nil?
end
memoize :uri
alias_method :url, :uri
# @return [String] The URL to the user's website.
def website
- Addressable::URI.parse(@attrs[:url]) if @attrs[:url]
+ Addressable::URI.parse(@attrs[:url]) unless @attrs[:url].nil?
end
memoize :website
@@ -58,9 +58,9 @@
expect(tweet.filter_level).to be_a String
expect(tweet.filter_level).to eq('high')
end
- it 'returns \'none\' when not set' do
+ it 'returns nil when not set' do
tweet = Twitter::Tweet.new(:id => 28_669_546_014)
- expect(tweet.filter_level).to eq('none')
+ expect(tweet.filter_level).to be nil
end
end

0 comments on commit 1304fb4

Please sign in to comment.