Class: Rotoworld::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/CLI.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headlineObject

Returns the value of attribute headline.



10
11
12
# File 'lib/CLI.rb', line 10

def headline
  @headline
end

#impactObject

Returns the value of attribute impact.



10
11
12
# File 'lib/CLI.rb', line 10

def impact
  @impact
end

#indexObject

Returns the value of attribute index.



10
11
12
# File 'lib/CLI.rb', line 10

def index
  @index
end

#sourceObject

Returns the value of attribute source.



10
11
12
# File 'lib/CLI.rb', line 10

def source
  @source
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/CLI.rb', line 10

def title
  @title
end

Instance Method Details

#callObject

Begins the Rotoworld gem by first scraping the data from the site, making Post objects from the data, and displaying the posts with options to read more, open site, and



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/CLI.rb', line 14

def call
  space
  puts "Welcome to Rotoworld NFL - Player News"
  puts "______________________________________"
  Rotoworld::Scraper.new.get_posts
  show_posts

  puts "Would you like to refresh or exit?"
  input = gets.strip
  if input.downcase == "refresh"
    call
  elsif input.downcase == "exit"
    system("clear")
    puts "Thanks for visiting."
    sleep(5)
    
  end
end

#show_postsObject

Takes data from the Scraper class that created Post objects. Iterates through the Post all array and displays the post title as well as a brief description of the headline. From there user is promted to view the source or move on, which opens the source in the user’s browser. After viewing the source, user has option to move on, go to ESPN Fantasy Football home page to make trade, or go to DraftKings and make a bet. User can refresh entire program, as well as exit at any time.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/CLI.rb', line 37

def show_posts

 
  puts "Here are the most recent updates!"
  puts "Type refresh at any time to refresh the newsfeed!"
  puts "___________________________________"
  sleep(5)

  
  Rotoworld::Post.all.each do |post|
    system("clear")
    puts "----------------------------------"
    puts post.index.to_s + ". " + post.title
    puts "----------------------------------"
    puts post.headline
    puts ""
    puts ""
    ###Prompt to view more on the site
    puts "Would you like to read more? (y/n) "
    input = gets.strip
    if input.downcase == "yes" || input.downcase == "y"
      puts ""
      puts ""
      puts post.impact
      puts ""
      puts ""
      ##### Source Prompt
      puts "Would you like to view the source? (y/n) "
      input2 = gets.strip
      if input2.downcase == "yes" || input2.downcase == "y"
        if post.source != nil
          Launchy.open(post.source.strip)
          sleep(5)
          puts
          ### ESPN Fantasy Football or Draftkings Prompt
          puts "Would you like to move on or exit? Or type fantasy to make a trade! Or type bet to go to DraftKings!"
          input3 = gets.strip
          if input3.downcase == "exit"
            break
          elsif input3.downcase == "fantasy"
            Launchy.open("http://games.espn.go.com/frontpage/football")
          elsif input3.downcase == "bet"
            Launchy.open("https://www.draftkings.com/")
          elsif input3.downcase == "move on"
            nil
          elsif input3.downcase == "refresh"
            call
          else
            nil
          end
        else
          puts "Source does not exist. Would you like to move on or exit? Or type fantasy to make a trade! Or type bet to go to DraftKings!"
          input3 = gets.strip
          if input3.downcase == "exit"
            break
          elsif input3.downcase == "fantasy"
            Launchy.open("http://games.espn.go.com/frontpage/football")
          elsif input3.downcase == "bet"
            Launchy.open("https://www.draftkings.com/")
          elsif input3.downcase == "move on"
            nil
          elsif input3.downcase == "refresh"
            call
          else
            nil
          end
        end
      elsif input2.downcase == "refresh"
        call
      elsif input2.downcase == "exit"
        break
      end
      
    elsif input.downcase == "n" || input.downcase == "no"
      nil
    
    elsif input.downcase == "refresh"
      call
    elsif input.downcase == "exit"
      break
    else
      nil
    end


  end
end

#spaceObject

Creates blank space for aesthetic appeal



125
126
127
128
129
# File 'lib/CLI.rb', line 125

def space
  20.times do
    puts ""
  end
end