Class: Gemline
- Inherits:
-
Object
- Object
- Gemline
- Defined in:
- lib/gemline.rb
Instance Attribute Summary collapse
-
#gem ⇒ Object
Returns the value of attribute gem.
-
#gemline ⇒ Object
Returns the value of attribute gemline.
-
#json ⇒ Object
Returns the value of attribute json.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #gem_not_found? ⇒ Boolean
-
#initialize(gem_name, options = {}) ⇒ Gemline
constructor
A new instance of Gemline.
- #sanitize_gem_name(gem_name) ⇒ Object
Constructor Details
#initialize(gem_name, options = {}) ⇒ Gemline
Returns a new instance of Gemline.
20 21 22 23 24 25 26 27 |
# File 'lib/gemline.rb', line 20 def initialize(gem_name, = {}) @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'], ) end end |
Instance Attribute Details
#gem ⇒ Object
Returns the value of attribute gem.
6 7 8 |
# File 'lib/gemline.rb', line 6 def gem @gem end |
#gemline ⇒ Object
Returns the value of attribute gemline.
6 7 8 |
# File 'lib/gemline.rb', line 6 def gemline @gemline end |
#json ⇒ Object
Returns the value of attribute json.
6 7 8 |
# File 'lib/gemline.rb', line 6 def json @json end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/gemline.rb', line 6 def response @response end |
Class Method Details
.query(gem_name, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gemline.rb', line 8 def self.query(gem_name, = {}) g = Gemline.new(gem_name, ) 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
33 34 35 |
# File 'lib/gemline.rb', line 33 def gem_not_found? !!@json.match(/(could not be found|does not exist)/) end |
#sanitize_gem_name(gem_name) ⇒ Object
29 30 31 |
# File 'lib/gemline.rb', line 29 def sanitize_gem_name(gem_name) gem_name.to_s.gsub(/[^\w\-]+/,'') # Yeah, a little over-defensive. end |