Class: RubyCat::Catalog

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCatalog

Returns a new instance of Catalog.



10
11
12
# File 'lib/rubycat/catalog.rb', line 10

def initialize
  @cards = []
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



8
9
10
# File 'lib/rubycat/catalog.rb', line 8

def cards
  @cards
end

Instance Method Details

#add(cards) ⇒ Object



14
15
16
# File 'lib/rubycat/catalog.rb', line 14

def add( cards )
  @cards +=  cards.map { |card| Card.new(card) }   ## convert to RubyCat card
end

#renderObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubycat/catalog.rb', line 40

def render
  ## render to json
  puts "--snip--"

  ary = []

  @cards.each do |card|
    h = card.to_hash
    ## pp h
    ary << h
  end

  puts "--snip--"
  puts JSON.pretty_generate( ary )
end

#sync(opts = {}) ⇒ Object

change name to populate/autofill, etc. ??



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubycat/catalog.rb', line 18

def sync( opts={} )   ## change name to populate/autofill, etc. ??
  ## get (extra) data from rubygems via api

  gems = RubyGemsService.new

  @cards.each_with_index do |card,i|

    if card.gem_url
      json = gems.info( card.name )
      pp json

      card.sync_gems_info( json )
    end

    pp card

    ### for debugging/testing; stop after processing x (e.g. 2) recs
    break    if opts[:limit] && i >= opts[:limit].to_i   ## e.g. i > 2 etc. 
  end
end