forked from bevry/staticsitegenerators-list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssg.rb
46 lines (39 loc) · 909 Bytes
/
ssg.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'date'
require 'octokit'
require 'yaml'
class SSG
attr_accessor :name, :language, :website, :github, :created_at
def initialize(hash)
hash.each { |k, v| instance_variable_set("@#{k}", v) }
get_missing_info_from_github if @github
end
def to_s
@name
end
def maturity
if @created_at
days = (Date.today - Date.parse(@created_at))
years = days / 365.242
if years < 1
'less than a year'
elsif years.round == 1
'about 1 year'
else
"about #{years.round} years"
end
end
end
private
def get_missing_info_from_github
repo = Octokit.repo(@github)
@created_at ||= repo.created_at
@github_followers ||= repo.watchers_count
@language ||= repo.language
end
end
YAML.load_file('list.yaml').take(4).each do |hash|
ssg = SSG.new(hash)
puts ssg.name
puts ssg.maturity
puts ssg.language
end