Module: Gems

Defined in:
lib/gemverse.rb,
lib/gemverse/api.rb,
lib/gemverse/gems.rb,
lib/gemverse/cache.rb,
lib/gemverse/timeline.rb

Defined Under Namespace

Modules: API Classes: Cache, Gem, GemDataset, Timeline

Class Method Summary collapse

Class Method Details

.find_by(owner:) ⇒ Object

“high-level” finders



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gemverse.rb', line 34

def self.find_by( owner: )  ## todo/check: use

  rows = API.gems_by( owner )
  # pp data
  puts "  #{rows.size} record(s) founds"

  ## write "raw respone" to cache for debugging
  write_json( "./cache/gems_#{owner}.json", rows )



  recs = []
  rows.each do |row|
     recs <<  Gem.create( row )
  end

  ## sort by
  ##  1) (latest) version created and
  ##  2) name
   recs = recs.sort do |l,r|
     res =  r.version_created <=> l.version_created
     res =  l.name            <=> r.name       if res == 0
     res
   end

  GemDataset.new( recs )
end

.read_csv(path) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gemverse.rb', line 64

def self.read_csv( path )
  ## note: requires Kernel::  otherwise stackoverflow endlessly calling read_csv
  rows = Kernel::read_csv( path )
  puts "  #{rows.size} record(s) founds"

  recs = []
  rows.each do |row|
     kwargs = {
      version: row['version'].empty? ? nil : row['version'],
      version_downloads: row['version_downloads'].empty? ? nil : row['version_downloads'].to_i,
      version_created:  row['version_created'].empty? ? nil : Date.strptime( row['version_created'], '%Y-%m-%d' ),
      homepage:  row['homepage'].empty? ? nil : row['homepage'],
      runtime:   row['dependencies'].empty? ? [] : row['dependencies'].split('|').map {|dep| dep.strip },
     }
     recs <<  Gem.new( name: row['name'], **kwargs )
  end

  ## sort by
  ##  1) (latest) version created and
  ##  2) name
   recs = recs.sort do |l,r|
     res =  r.version_created <=> l.version_created
     res =  l.name            <=> r.name     if res == 0
     res
   end

  GemDataset.new( recs )
end