Class: CombineHashtags::View

Inherits:
Object
  • Object
show all
Defined in:
lib/combine_hashtags/cli/view.rb

Overview

View class for CLI display

Instance Method Summary collapse

Constructor Details

#initializeView

Returns a new instance of View.



3
4
5
6
7
# File 'lib/combine_hashtags/cli/view.rb', line 3

def initialize
  @tags = {}
  @list = "These are your 10 most popular hashtags:"
  @search = "Showing X results:"
end

Instance Method Details



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/combine_hashtags/cli/view.rb', line 33

def links(results)
  results.each_with_index do |value, index|
    preview = value.caption.gsub("\n", "").scan(/^[a-zA-Z\s\S][^#@]*/)
    puts ""
    puts "  #{index + 1} - Post preview:"
    puts "  #{preview.first}"
    puts "  Other hashtags:"

    preview_tags(value.tags)
    
    puts ""
    puts "  Go to => #{value.post_url}"
    puts " "
    puts "* * * * * * * * * * * * * * * * * * * * * *"
  end
end

#preview_tags(tags) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/combine_hashtags/cli/view.rb', line 50

def preview_tags(tags)
  # TODO: refactor... chaining methods mehhhhh?
  group = tags.split(" ").sample(10).each_slice(5).to_a
  group.each do |set| 
    puts "    #{set.to_s}" 
  end
end

#results(results) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/combine_hashtags/cli/view.rb', line 25

def results(results)
  @search.gsub!("X", results.size.to_s)
  title("search")
  puts ""
  links(results)
  puts ""
end

#searchObject



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/combine_hashtags/cli/view.rb', line 58

def search
  puts "Type the 1st hashtag you would like to search with"
  puts ">"
  @tags[:first] = gets.chomp
  # yield if block_given?
  puts "Type the 2nd hashtag you would like to search with"
  puts ">"
  @tags[:second] = gets.chomp
  puts "Enter a 3rd hashtag, or press enter to skip"
  @tags[:third] = gets.chomp
  @tags
end

#tags(content) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/combine_hashtags/cli/view.rb', line 17

def tags(content)
  title("list")
  content.each_with_index do |value, index|
    puts "  #{index + 1} - #{value[0]} appears #{value[1]} times in this profile"
    puts ""
  end
end

#title(type) ⇒ Object

formatting title appearance in CLI



10
11
12
13
14
15
# File 'lib/combine_hashtags/cli/view.rb', line 10

def title(type)
  title = type == "list" ? @list : @search
  puts "  --------------------------------------------"
  puts "    #{title}"
  puts "  --------------------------------------------"
end