Class: Bjt::Jumper

Inherits:
Object
  • Object
show all
Defined in:
lib/bjt/jumper.rb

Defined Under Namespace

Classes: UnknownEventError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, package) ⇒ Jumper

Returns a new instance of Jumper.



7
8
9
10
# File 'lib/bjt/jumper.rb', line 7

def initialize(event, package)
  @event = event
  @package = package
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



5
6
7
# File 'lib/bjt/jumper.rb', line 5

def event
  @event
end

#packageObject (readonly)

Returns the value of attribute package.



5
6
7
# File 'lib/bjt/jumper.rb', line 5

def package
  @package
end

Instance Method Details

#jumpObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bjt/jumper.rb', line 12

def jump
  case event
  when :g, :s then Browser.new(info[:source_code_uri]).open
  when :h then Browser.new(info[:homepage]).open
  when :p then Browser.new(info[:package_uri]).open
  when :r then Browser.new(info[:release_uri]).open
  when :d then Browser.new(info[:doc_uri]).open
  when :l then system(command(info[:gem_path]))
  else raise UnknownEventError, package
  end
rescue Bjt::Fetcher::NotFoundPackageError => e
  puts "[ERROR] not found this package: #{package}, please make sure this package installed"
rescue Bjt::Jumper::UnknownEventError => e
  puts "[ERROR] unknown event: #{event}, support g s h p r d l events"
rescue StandardError => e
  puts "[ERROR] has error: #{e.message}"
end