Class: CombineHashtags::View
- Inherits:
-
Object
- Object
- CombineHashtags::View
- Defined in:
- lib/combine_hashtags/cli/view.rb
Overview
View class for CLI display
Instance Method Summary collapse
-
#initialize ⇒ View
constructor
A new instance of View.
- #links(results) ⇒ Object
- #preview_tags(tags) ⇒ Object
- #results(results) ⇒ Object
- #search ⇒ Object
- #tags(content) ⇒ Object
-
#title(type) ⇒ Object
formatting title appearance in CLI.
Constructor Details
#initialize ⇒ View
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
#links(results) ⇒ Object
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:" (value.) 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 () # TODO: refactor... chaining methods mehhhhh? group = .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 |
#search ⇒ Object
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 (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 |