Class: Bmo2::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/bmo2/platform.rb

Class Method Summary collapse

Class Method Details

.copy(item) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/bmo2/platform.rb', line 47

def copy(item)
  begin
    IO.popen(copy_command,"w") {|cc|  cc.write(item.value)}
    item.value
  rescue Errno::ENOENT
    puts item.value
    puts "Please install #{copy_command[0..5]} to copy this item to your clipboard"
    exit
  end
end

.copy_commandObject



37
38
39
40
41
42
43
44
45
# File 'lib/bmo2/platform.rb', line 37

def copy_command
  if darwin?
    'pbcopy'
  elsif windows? || cygwin?
    'clip'
  else
    'xclip -selection clipboard'
  end
end

.cygwin?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/bmo2/platform.rb', line 4

def cygwin?
  !!(RbConfig::CONFIG['host_os'] =~ /cygwin/)
end

.darwin?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/bmo2/platform.rb', line 7

def darwin?
  !!(RbConfig::CONFIG['host_os'] =~ /darwin/)
end

.edit(json_file) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bmo2/platform.rb', line 58

def edit(json_file)
  unless ENV['EDITOR'].nil?
    unless windows?
      system("`echo $EDITOR` #{json_file} &")
    else
      system("start %EDITOR% #{json_file}")
    end
  else
    system("#{open_command} #{json_file}")
  end

  "Make your edits, and do be sure to save."
end

.open(item) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/bmo2/platform.rb', line 27

def open(item)
  unless windows?
    system("#{open_command} '#{item.url.gsub("\'","'\\\\''")}'")
  else
    system("#{open_command} #{item.url.gsub("\'","'\\\\''")}")
  end

  item.value
end

.open_commandObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bmo2/platform.rb', line 15

def open_command
  if darwin?
    'open'
  elsif windows?
    'start'
  elsif cygwin?
    'cygstart'
  else
    'xdg-open'
  end
end

.windows?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/bmo2/platform.rb', line 11

def windows?
  !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
end