Class: IsIt19

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

Overview

Utilities for determining if a Gem::Specification is ruby 1.9 ready. Based on http://isitruby19.com

Constant Summary collapse

VERSION =

This version of rubygems-isit19

'1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ IsIt19

Downloads comments for spec from http://isitruby19.com



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/isit19.rb', line 29

def initialize(spec)
  @spec = spec

  url = URI.parse "http://isitruby19.com/#{@spec.name}/comments.json"

  json = Gem::RemoteFetcher.fetcher.fetch_path url
  comments = JSON.parse json

  comments.map! do |comment|
    begin
      comment['comment']['version'] =
        Gem::Version.new comment['comment']['version']
      comment['comment']
    rescue ArgumentError # bad data from isitruby19.com
      next
    end
  end

  comments.compact!

  @comments = comments.sort_by do |comment|
    works = comment['works_for_me'] ? 1 : 0
    [comment['version'], works, comment['name']]
  end.reverse
end

Instance Attribute Details

#commentsObject (readonly)

Comments for this gem



19
20
21
# File 'lib/isit19.rb', line 19

def comments
  @comments
end

#specObject (readonly)

The gemspec



24
25
26
# File 'lib/isit19.rb', line 24

def spec
  @spec
end

Instance Method Details

#maybe_one_nine?Boolean

Returns a comment from the latest version that worked with 1.9



67
68
69
70
71
# File 'lib/isit19.rb', line 67

def maybe_one_nine?
  @comments.first do |comment|
    comment['works_for_me']
  end
end

#one_nine?Boolean

Strict check for this version



58
59
60
61
62
# File 'lib/isit19.rb', line 58

def one_nine?
  @comments.any? do |comment|
    comment['version'] == @spec.version and comment['works_for_me']
  end
end

#percent(version = @spec.version) ⇒ Object

Returns a percentage of people saying version worked for them



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/isit19.rb', line 76

def percent(version = @spec.version)
  matching = @comments.select do |comment|
    comment['version'] == version
  end

  works = matching.select do |comment| comment['works_for_me'] end.length

  percent = (matching.length.to_f / works * 100)
  percent = 0   if percent.nan?
  percent = 100 if percent > 100

  "%2.0f%%" % percent
end

#urlObject

URL of this gem on http://isitruby19.com



93
94
95
# File 'lib/isit19.rb', line 93

def url
  "http://isitruby19.com/#{spec.name}"
end