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 isitruby19.com

Direct Known Subclasses

IsItJruby

Constant Summary collapse

VERSION =

This version of rubygems-isit19

'1.1.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ IsIt19

Downloads comments for spec from isitruby19.com



29
30
31
# File 'lib/isit19.rb', line 29

def initialize(spec)
  @spec = spec
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

#are_there_comments?Boolean

Whether are the any comments

Returns:

  • (Boolean)


84
85
86
# File 'lib/isit19.rb', line 84

def are_there_comments?
  @comments.size > 0
end

#fetch!Object



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

def fetch!
  comments_url = URI.parse "#{url}/comments.json"

  json = Gem::RemoteFetcher.fetcher.fetch_path comments_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

#is_it_for_sure?Boolean

Strict check for this version

Returns:

  • (Boolean)


60
61
62
63
64
# File 'lib/isit19.rb', line 60

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

#maybe_is_it?Boolean

Returns a comment from the latest version that worked with 1.9

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/isit19.rb', line 69

def maybe_is_it?
  @comments.detect do |comment|
    comment['works_for_me']
  end
end

#more_recentObject

Returns the more recent comment about this gem



78
79
80
# File 'lib/isit19.rb', line 78

def more_recent  
  @comments.sort.last if are_there_comments?
end

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

Returns a percentage of people saying version worked for them



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/isit19.rb', line 91

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

#platformObject



112
113
114
# File 'lib/isit19.rb', line 112

def platform
  "1.9"
end

#urlObject

URL of this gem on isitruby19.com



108
109
110
# File 'lib/isit19.rb', line 108

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