Class: Hackershout::Base

Inherits:
Object
  • Object
show all
Includes:
Output
Defined in:
lib/hackershout/base.rb

Instance Method Summary collapse

Methods included from Output

#blank, #print

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
# File 'lib/hackershout/base.rb', line 7

def initialize(options = {})
  @url = options[:url]
  @title = options[:title]
  @message = options[:message]
  @tags = options[:tags] || []
  @providers = options[:providers] || []
end

Instance Method Details

#ask_for_messageObject



42
43
44
45
46
47
48
49
50
# File 'lib/hackershout/base.rb', line 42

def ask_for_message
  print "Bear in mind that some services may require a more extended text aside from the title."
  print "Type your message (two ENTERs to finish): "
  $/ = "\n\n"
  gets.chomp.strip.tap do
    # Restore EOM char
    $/ = "\n"
  end
end

#ask_for_providersObject



61
62
63
64
65
# File 'lib/hackershout/base.rb', line 61

def ask_for_providers
  Provider.list.keys.select do |provider|
    Provider.wants?(provider)
  end
end

#ask_for_tagsObject



52
53
54
55
# File 'lib/hackershout/base.rb', line 52

def ask_for_tags
  print "Type some tags separated by comma (i.e. ruby, rails, bdd): "
  gets.chomp.strip.split(',').map(&:strip)
end

#ask_for_titleObject



37
38
39
40
# File 'lib/hackershout/base.rb', line 37

def ask_for_title
  print "Enter a brief, descriptive title: "
  gets.chomp.strip
end

#ask_for_urlObject



32
33
34
35
# File 'lib/hackershout/base.rb', line 32

def ask_for_url
  print "Type the URL you want to share: "
  gets.chomp.strip << "?utm_source=hackershout"
end

#post_to_providersObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/hackershout/base.rb', line 67

def post_to_providers
  print "Fine."
  @providers.map do |provider|
    eval("Provider::#{provider.capitalize}").new({ 
      url:     @url,
      title:   @title,
      message: @message,
      tags:    @tags,
    })
  end.each do |provider|
    provider.publish
  end
  puts "Done. Happy hacking! :)\n"
end

#providers_bannerObject



57
58
59
# File 'lib/hackershout/base.rb', line 57

def providers_banner
  print "...Got it! Now where would you want to spread the word?"
end

#runObject



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

def run
  welcome_banner
  @url = ask_for_url
  @title = ask_for_title
  @message = ask_for_message
  @tags = ask_for_tags
  providers_banner

  @providers = ask_for_providers
  post_to_providers
end

#welcome_bannerObject



27
28
29
30
# File 'lib/hackershout/base.rb', line 27

def welcome_banner
  print ":: Welcome to hackershout! ::"
  blank
end