Class: Metalbird::Twitter::PublishArgs

Inherits:
Object
  • Object
show all
Defined in:
lib/metalbird/twitter/publish_args.rb

Constant Summary collapse

MAX_TWEET_LENGTH =
140
IMAGE_LENGTH =
23
23
4
MAX_IMAGE_COUNT =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, link_processor = nil) ⇒ PublishArgs

Returns a new instance of PublishArgs



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/metalbird/twitter/publish_args.rb', line 15

def initialize(data, link_processor = nil)
  fail NoTweetError unless data[:tweet]

  analyzed_tweet = analyze_tweet(data[:tweet])
  @tweet = analyzed_tweet[:tweet]
  @url_processor = link_processor || Metalbird::UrlProcessor::Default.new
  @links = ((data[:links] || []) + analyzed_tweet[:links]).uniq
  @links = process_links
  @images = data[:images] || []
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors



13
14
15
# File 'lib/metalbird/twitter/publish_args.rb', line 13

def errors
  @errors
end

#imagesObject (readonly)

Returns the value of attribute images



13
14
15
# File 'lib/metalbird/twitter/publish_args.rb', line 13

def images
  @images
end

Returns the value of attribute links



13
14
15
# File 'lib/metalbird/twitter/publish_args.rb', line 13

def links
  @links
end

Instance Method Details

#image_countObject



51
52
53
# File 'lib/metalbird/twitter/publish_args.rb', line 51

def image_count
  images.length
end

#images?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/metalbird/twitter/publish_args.rb', line 43

def images?
  true if images.length > 0
end


55
56
57
# File 'lib/metalbird/twitter/publish_args.rb', line 55

def link_count
  links.length
end

#links?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/metalbird/twitter/publish_args.rb', line 47

def links?
  true if links.length > 0
end

#tweetObject



27
28
29
30
# File 'lib/metalbird/twitter/publish_args.rb', line 27

def tweet
  return @tweet.strip + ' ' + links.join(' ') if links?
  @tweet
end

#validate?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
# File 'lib/metalbird/twitter/publish_args.rb', line 32

def validate?
  @errors = []

  validate_not_empty &&
    validate_image_count &&
    validate_link_count &&
    validate_length &&
    validate_images &&
    validate_links
end