Class: Twuckoo::OneLineFromFile
- Inherits:
-
Object
- Object
- Twuckoo::OneLineFromFile
- Defined in:
- lib/twuckoo/feeders/one_line_from_file.rb
Constant Summary collapse
- LINES_FILE =
'lines.txt'
- USED_LINES_FILE =
'used_lines.txt'
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
store used strategies in a file with (store the md5 sum of the strategies’ text).
Instance Method Summary collapse
- #add_lines(*new_lines) ⇒ Object
- #get_all_lines ⇒ Object
- #get_lines_from_file ⇒ Object
- #get_unused_lines ⇒ Object
- #get_used_lines ⇒ Object
- #get_used_lines_from_file ⇒ Object
-
#initialize(tweeter_module) ⇒ OneLineFromFile
constructor
A new instance of OneLineFromFile.
- #load_lines ⇒ Object
-
#load_tweets ⇒ Object
TODO: This could be merged into setup.
- #next ⇒ Object
- #pick ⇒ Object
- #reset ⇒ Object
- #setup ⇒ Object
- #store(line) ⇒ Object
Constructor Details
#initialize(tweeter_module) ⇒ OneLineFromFile
Returns a new instance of OneLineFromFile.
13 14 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 13 def initialize(tweeter_module) end |
Instance Attribute Details
#lines ⇒ Object (readonly)
store used strategies in a file with (store the md5 sum of the strategies’ text)
8 9 10 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 8 def lines @lines end |
Instance Method Details
#add_lines(*new_lines) ⇒ Object
53 54 55 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 53 def add_lines(*new_lines) @lines.concat(new_lines) end |
#get_all_lines ⇒ Object
29 30 31 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 29 def get_all_lines @fresh_lines ||= get_lines_from_file end |
#get_lines_from_file ⇒ Object
25 26 27 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 25 def get_lines_from_file IO::readlines(LINES_FILE).map { |line| line.chomp } end |
#get_unused_lines ⇒ Object
45 46 47 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 45 def get_unused_lines get_all_lines.reject { |line| get_used_lines.include?(line) } end |
#get_used_lines ⇒ Object
41 42 43 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 41 def get_used_lines @used_lines ||= get_used_lines_from_file end |
#get_used_lines_from_file ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 33 def get_used_lines_from_file begin IO::readlines(USED_LINES_FILE).map { |line| line.chomp } rescue Errno::ENOENT [] end end |
#load_lines ⇒ Object
49 50 51 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 49 def load_lines add_lines(*get_unused_lines) end |
#load_tweets ⇒ Object
TODO: This could be merged into setup
21 22 23 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 21 def load_tweets load_lines end |
#next ⇒ Object
67 68 69 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 67 def next @lines.delete_at(pick) end |
#pick ⇒ Object
57 58 59 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 57 def pick rand(lines.length) end |
#reset ⇒ Object
71 72 73 74 75 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 71 def reset File.delete(USED_LINES_FILE) rescue nil @used_lines = nil load_lines end |
#setup ⇒ Object
16 17 18 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 16 def setup @lines = [] end |
#store(line) ⇒ Object
61 62 63 64 65 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 61 def store(line) open(USED_LINES_FILE, "a") do |file| file.write(line + "\n") end end |