Class: Hackershout::Base
- Inherits:
-
Object
- Object
- Hackershout::Base
- Includes:
- Output
- Defined in:
- lib/hackershout/base.rb
Instance Method Summary collapse
- #ask_for_message ⇒ Object
- #ask_for_providers ⇒ Object
- #ask_for_tags ⇒ Object
- #ask_for_title ⇒ Object
- #ask_for_url ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #post_to_providers ⇒ Object
- #providers_banner ⇒ Object
- #run ⇒ Object
- #welcome_banner ⇒ Object
Methods included from Output
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( = {}) @url = [:url] @title = [:title] @message = [:message] @tags = [:tags] || [] @providers = [:providers] || [] end |
Instance Method Details
#ask_for_message ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/hackershout/base.rb', line 42 def 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_providers ⇒ Object
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_tags ⇒ Object
52 53 54 55 |
# File 'lib/hackershout/base.rb', line 52 def print "Type some tags separated by comma (i.e. ruby, rails, bdd): " gets.chomp.strip.split(',').map(&:strip) end |
#ask_for_title ⇒ Object
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_url ⇒ Object
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_providers ⇒ Object
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_banner ⇒ Object
57 58 59 |
# File 'lib/hackershout/base.rb', line 57 def print "...Got it! Now where would you want to spread the word?" end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hackershout/base.rb', line 15 def run @url = ask_for_url @title = ask_for_title @message = @tags = @providers = ask_for_providers post_to_providers end |
#welcome_banner ⇒ Object
27 28 29 30 |
# File 'lib/hackershout/base.rb', line 27 def print ":: Welcome to hackershout! ::" blank end |