Class: GhContributors

Inherits:
Object
  • Object
show all
Defined in:
lib/gh_contributors/version.rb,
lib/gh_contributors.rb

Overview

/usr/bin/env ruby

Constant Summary collapse

DEFAULT_URL_FORMAT =
%q{%Q{<a href="#{data['url']}" title="#{login} - #{data['contributions']}"><img src="#{data['avatar_url']}" alt="#{login} - #{data['contributions']}"/></a>}}
DEFAULT_SEARCH =
/<span class="contributors">.*?<\/span>/m
DEFAULT_REPLACE =
%q{%Q{<span class="contributors">\n#{@data.join("\n")}\n</span>}}
VERSION =
"0.8.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



22
23
24
# File 'lib/gh_contributors.rb', line 22

def data
  @data
end

Class Method Details

.for_org(name) ⇒ Object

for_org(‘railsinstaller’)



25
26
27
# File 'lib/gh_contributors.rb', line 25

def self.for_org(name)
  GhContributors.new.for_org(name)
end

.for_repo(name) ⇒ Object

for_repo(‘railsinstaller/webapp’)



38
39
40
# File 'lib/gh_contributors.rb', line 38

def self.for_repo(name)
  GhContributors.new.for_repo(name)
end

Instance Method Details

#for_org(name) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/gh_contributors.rb', line 28

def for_org(name)
  @data = load_json(url_builder("orgs/#{name}/repos")).map{ |repo|
    log "repository: #{name}/#{repo['name']}"
    load_json(repo['contributors_url'])
  }.inject(&:+)
  calculate
  self
end

#for_repo(name) ⇒ Object



41
42
43
44
45
46
# File 'lib/gh_contributors.rb', line 41

def for_repo(name)
  log "repository: #{name}"
  @data = load_json(url_builder("repos/#{name}/contributors"))
  calculate
  self
end

#to_urls(format = GhContributors::DEFAULT_URL_FORMAT) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gh_contributors.rb', line 48

def to_urls(format=GhContributors::DEFAULT_URL_FORMAT)
  @data.map! {|, data|
    log "user: #{} - #{data['contributions']}"
    if block_given?
      yield , data
    else
      eval format
    end
  }
  self
end

#update_files(*files) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gh_contributors.rb', line 60

def update_files(*files)
  options = files.last.kind_of?(Hash) ? files.pop : {}
  options[:search]  ||= DEFAULT_SEARCH
  options[:replace] ||= DEFAULT_REPLACE
  files = files.first if files.first.kind_of? Array
  files.each do |file|
    log "file: #{file}"
    update_file(file) do |text|
      if block_given?
        text = yield text, @data, file
      else
        text.sub(options[:search], eval(options[:replace]))
      end
    end
  end
  self
end