Class: Mru::Fuf::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/mru/fuf/data.rb

Class Method Summary collapse

Class Method Details

.load(type, limit: 1000, reverse: false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mru/fuf/data.rb', line 5

def self.load(type, limit: 1000, reverse: false)
  path = path_of_type(type)
  raise "Nothing Dir: [#{DIR}]" unless Dir.exist? DIR
  raise "Nothing File: #{path}" unless File.readable? path

  range = reverse ? (limit * -1)..-1 : 0..limit 

  buf = []
  IO.readlines(path)[range].tap{|x| break x.reverse if reverse }.each do |line|
    buf << YAML.load(line)['word']
  end
  buf
end

.path_of_type(type) ⇒ Object



19
20
21
# File 'lib/mru/fuf/data.rb', line 19

def self.path_of_type(type)
  "#{DIR}/#{type}"
end