Class: Gemline

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_name, options = {}) ⇒ Gemline

Returns a new instance of Gemline.



19
20
21
22
23
24
25
26
# File 'lib/gemline.rb', line 19

def initialize(gem_name, options = {})
  @gem = sanitize_gem_name(gem_name)
  @json = Gemline.get_rubygem_json(@gem)
  unless gem_not_found?
    @response = JSON.parse(@json)
    @gemline = Gemline.create_gemline(@gem, response['version'], options)
  end
end

Instance Attribute Details

#gemObject

Returns the value of attribute gem.



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

def gem
  @gem
end

#gemlineObject

Returns the value of attribute gemline.



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

def gemline
  @gemline
end

#jsonObject

Returns the value of attribute json.



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

def json
  @json
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Class Method Details

.query(gem_name, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gemline.rb', line 7

def self.query(gem_name, options = {})
  g = Gemline.new(gem_name, options)

  if g.gem_not_found?
    $stderr.puts "Ruby gem #{gem_name} was not found on rubygems.org"
    Kernel.exit 1
  else
    puts g.gemline
    copy_to_clipboard(g.gemline)
  end
end

Instance Method Details

#gem_not_found?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/gemline.rb', line 32

def gem_not_found?
  !!@json.match(/(could not be found|does not exist)/)
end

#sanitize_gem_name(gem_name) ⇒ Object



28
29
30
# File 'lib/gemline.rb', line 28

def sanitize_gem_name(gem_name)
  gem_name.to_s.gsub(/[^\w\-]+/,'') # Yeah, a little over-defensive.
end