Class: RubyCat::Card

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(card) ⇒ Card

Returns a new instance of Card.



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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rubycat/card.rb', line 35

def initialize( card )
  @categories = card.categories
  @name = nil


  github_link = card.links.find {|it| it[0].include?( ':octocat:') }
  
  if github_link
    @github_url = github_link[1]
    
    ## check if org (shortcut)
    uri = URI.parse( @github_url )
      puts "  uri.path: #{uri.path}"
      ##
      names = uri.path[1..-1].split('/')  ## cut off leading / and split
      pp names

      ## if single name (duplicate - downcased! e.g. Ramaze => Ramaze/ramaze)
      if names.size == 1
        @github_url += "/#{names[0].downcase}"
        @name = names[0].downcase
      else
        @name = names[1]
      end
      puts "github_url: #{@github_url}"
  else
      puts "*** no github_url found"
      pp card
  end

  gem_link  = card.links.find {|it| it[0] == ':gem:' }
  if gem_link
    @gem_url = gem_link[1]
    puts "gem_url: #{@gem_url}"

    uri = URI.parse( @gem_url )
    names = uri.path[1..-1].split('/')  ## cut off leading / and split
    pp names
    ## assume last name entry is name of gem
    @name = names[-1]
  else
    puts "*** no gem_url found"
    pp card
  end
end

Instance Attribute Details

#categoriesObject (readonly)

e.g.



12
13
14
# File 'lib/rubycat/card.rb', line 12

def categories
  @categories
end

#depsObject (readonly)

runtime dependencies as a string for now (activerecord, activesupport etc.)



18
19
20
# File 'lib/rubycat/card.rb', line 18

def deps
  @deps
end

#descObject (readonly)

info/blurb/description/summary (use summary ??)



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

def desc
  @desc
end

#downloadsObject (readonly)

total downloads



17
18
19
# File 'lib/rubycat/card.rb', line 17

def downloads
  @downloads
end

#gem_urlObject (readonly)



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

def gem_url
  @gem_url
end

#github_urlObject (readonly)



11
12
13
# File 'lib/rubycat/card.rb', line 11

def github_url
  @github_url
end

#latest_versionObject (readonly)

as string



15
16
17
# File 'lib/rubycat/card.rb', line 15

def latest_version
  @latest_version
end

#latest_version_downloadsObject (readonly)

Returns the value of attribute latest_version_downloads.



16
17
18
# File 'lib/rubycat/card.rb', line 16

def latest_version_downloads
  @latest_version_downloads
end

#nameObject (readonly)

read only



9
10
11
# File 'lib/rubycat/card.rb', line 9

def name
  @name
end

Instance Method Details

#sync_gems_info(json) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rubycat/card.rb', line 82

def sync_gems_info( json )
  @desc                      = json['info']
  @latest_version            = json['version']
  @latest_version_downloads  = json['version_downloads']
  @downloads                 = json['downloads']

  deps_runtime = json['dependencies']['runtime']
  if deps_runtime && deps_runtime.size > 0
    deps = []
    deps_runtime.each do |dep|
      deps << dep['name']
    end
    @deps = deps.join(', ')
  else
    @deps = nil
  end
end

#to_hashObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rubycat/card.rb', line 21

def to_hash
  { name:           @name,
    gem_url:        @gem_url,
    github_url:     @github_url,
    categories:     @categories,
    desc:           @desc,
    latest_version: @latest_version,
    latest_version_downloads: @latest_version_downloads,
    downloads:      @downloads,
    deps:           @deps }
end