Class: Museum::Loupe

Inherits:
ApplicationRecord
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/museum/loupe.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.id_by_slug(name) ⇒ Object



8
9
10
# File 'app/models/museum/loupe.rb', line 8

def self.id_by_slug(name)
  ( find_by_slug(name) || abort(name) ).id
end

Instance Method Details

#magnify(gem) ⇒ Object



12
13
14
# File 'app/models/museum/loupe.rb', line 12

def magnify(gem)
  parse_as(data_format, response(gem))
end

#parse_as(format, string) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/museum/loupe.rb', line 24

def parse_as(format, string)
  begin
    case format
      when 'json'
        JSON.parse string.to_s
      when 'yaml'
        YAML.parse string.to_s
      when 'xml'
        Hash.from_xml(string.to_s)
    end
  rescue
    {}
  end
end

#response(gem) ⇒ Object



20
21
22
# File 'app/models/museum/loupe.rb', line 20

def response(gem)
  url(gem).fetch
end

#url(gem) ⇒ Object



16
17
18
# File 'app/models/museum/loupe.rb', line 16

def url(gem)
  uri_template % { :name => gem.name, :user => Museum.configuration.username }
end