Module: ScoutHelpers

Defined in:
lib/scout-helpers.rb,
lib/scout-helpers/version.rb

Constant Summary collapse

VERSION =
"0.0.5"

Class Method Summary collapse

Class Method Details

.get_current_file(path, category) ⇒ Object

returns current file for a category



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/scout-helpers.rb', line 6

def self.get_current_file(path, category)
  path = path.slice(0, path.size - 1) if path.end_with?('/')
  File.new(
    "#{path}/#{category}/" +
    Dir.entries("#{path}/#{category}")
      .select {|item| item.match(category)}
      .reject {|item| item.match("#{category}_current")}
      .sort
      .last
  )
end

.get_last_file(path, category) ⇒ Object

returns last complete file for a category



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/scout-helpers.rb', line 20

def self.get_last_file(path, category)
  path = path.slice(0, path.size - 1) if path.end_with?('/')
  File.new(
    "#{path}/#{category}/" +
    Dir.entries("#{path}/#{category}")
      .select {|item| item.match(category)}
      .reject {|item| item.match("#{category}_current")}
      .sort
      .fetch(-2)
  )
end