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.
19 20 21 22 23 24 25 26 |
# File 'lib/gemline.rb', line 19 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.
5 6 7 |
# File 'lib/gemline.rb', line 5 def gem @gem end |
#gemline ⇒ Object
Returns the value of attribute gemline.
5 6 7 |
# File 'lib/gemline.rb', line 5 def gemline @gemline end |
#json ⇒ Object
Returns the value of attribute json.
5 6 7 |
# File 'lib/gemline.rb', line 5 def json @json end |
#response ⇒ Object
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, = {}) 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
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 |