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
- #load_lines ⇒ Object
-
#load_tweets ⇒ Object
TODO: This could be merged into setup.
- #next ⇒ Object
- #pick ⇒ Object
- #reset ⇒ Object
- #setup ⇒ Object
- #store(line) ⇒ Object
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
50 51 52 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 50 def add_lines(*new_lines) @lines.concat(new_lines) end |
#get_all_lines ⇒ Object
26 27 28 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 26 def get_all_lines @fresh_lines ||= get_lines_from_file end |
#get_lines_from_file ⇒ Object
22 23 24 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 22 def get_lines_from_file IO::readlines(LINES_FILE).map { |line| line.chomp } end |
#get_unused_lines ⇒ Object
42 43 44 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 42 def get_unused_lines get_all_lines.reject { |line| get_used_lines.include?(line) } end |
#get_used_lines ⇒ Object
38 39 40 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 38 def get_used_lines @used_lines ||= get_used_lines_from_file end |
#get_used_lines_from_file ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 30 def get_used_lines_from_file begin IO::readlines(USED_LINES_FILE).map { |line| line.chomp } rescue Errno::ENOENT [] end end |
#load_lines ⇒ Object
46 47 48 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 46 def load_lines add_lines(*get_unused_lines) end |
#load_tweets ⇒ Object
TODO: This could be merged into setup
18 19 20 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 18 def load_tweets load_lines end |
#next ⇒ Object
64 65 66 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 64 def next @lines.delete_at(pick) end |
#pick ⇒ Object
54 55 56 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 54 def pick rand(lines.length) end |
#reset ⇒ Object
68 69 70 71 72 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 68 def reset File.delete(USED_LINES_FILE) rescue nil @used_lines = nil load_lines end |
#setup ⇒ Object
13 14 15 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 13 def setup @lines = [] end |
#store(line) ⇒ Object
58 59 60 61 62 |
# File 'lib/twuckoo/feeders/one_line_from_file.rb', line 58 def store(line) open(USED_LINES_FILE, "a") do |file| file.write(line + "\n") end end |