Module: IdsPlease::CLI
- Defined in:
- lib/ids_please/cli.rb
Class Method Summary collapse
- .grab(ids) ⇒ Object
- .help ⇒ Object
- .parse(ids) ⇒ Object
- .recognize(ids) ⇒ Object
- .run(args) ⇒ Object
Class Method Details
.grab(ids) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ids_please/cli.rb', line 32 def grab(ids) ids.grab ids.grabbed.each do |, grabbers_array| puts .to_s.capitalize + ': ' grabbers_array.each do |grabber| grabber.to_h.each do |property, value| unless value.nil? || value.to_s.empty? || property == :page_source if value.class == Hash value.delete_if { |_, v| v.nil? } unless value.empty? puts " #{property}: " value.each do |k, v| puts " #{k}: #{v}" end end else puts " #{property}: #{value}" end end end puts "\n" unless grabbers_array.last == grabber end puts "\n" unless ids.grabbed.to_a.last[0] == end end |
.help ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ids_please/cli.rb', line 92 def help puts <<-HELP.gsub(/^ {8}/, '') IDs, please Grab some hidden in html data from social account page Get social network IDs or screen names from links to social network accounts Usage: ids_please command [links] Available commands: grab grab some hidden in html data from social account page (avatar, username, id...) parse get screen names from links to social network accounts recognize check that the link is for a known social network Examples: ids_please grab https://instagram.com/microsoft ids_please parse https://facebook.com/Microsoft https://instagram.com/microsoft HELP end |
.parse(ids) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ids_please/cli.rb', line 60 def parse(ids) ids.parse ids.parsed.each do |, permalinks_array| puts .to_s.capitalize + ': ' permalinks_array.each do |permalink| puts " #{permalink}" end puts "\n" unless ids.parsed.to_a.last[0] == end end |
.recognize(ids) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ids_please/cli.rb', line 71 def recognize(ids) ids.recognize unless ids.recognized.empty? puts 'Recognized:' ids.recognized.each do |, urls_array| puts " #{.to_s.capitalize}: " urls_array.each do |url| puts " #{url}" end puts "\n" end end unless ids.unrecognized.empty? puts 'Unrecognized:' ids.unrecognized.each do |url| puts " #{url}" end end end |
.run(args) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ids_please/cli.rb', line 3 def self.run(args) command = args.shift case command when 'grab', 'parse', 'recognize' when 'help', nil help exit else abort "Unknown command. Enter 'ids_please help' for instructions" end links = args if links.empty? abort "You didn't enter any links. Enter 'ids_please help' for instructions" end ids = IdsPlease.new(*links) case command when 'grab' grab(ids) when 'parse' parse(ids) when 'recognize' recognize(ids) end end |