Class: Memo::Cli::Command::Preview

Inherits:
Object
  • Object
show all
Defined in:
lib/memo/cli/command/preview.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, os: Memo::OS.new) ⇒ Preview

Returns a new instance of Preview.



5
6
7
8
9
10
11
12
13
14
# File 'lib/memo/cli/command/preview.rb', line 5

def initialize(
  options,
  os: Memo::OS.new
)
  @options = options
  @os = os
  @config = Memo::Config.new
  @today = Memo::Today.new
  @defaultfile = Memo::File.new
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/memo/cli/command/preview.rb', line 16

def call
  filename = @options[0]

  path = case filename
         when "today", "t"
           "#{@config.root}/#{@today.fullpath}"
         when "config", "c"
           @config.path
         else
           p = Memo::File.new(
             filename,
             @options.namespace,
           ).fullpath

           "#{@config.root}/#{p}"
         end

  cmd ="#{@config.preview} #{path}"
  if @options.copy?
    @os.exec "#{cmd} | (#{@config.pbcopy})"
  end

  @os.exec cmd
end