Sha256: d95c4a466c096633d0dc9656dceac69e0fe24b53ad8fa4729b445d215b76f260

Contents?: true

Size: 769 Bytes

Versions: 8

Compression:

Stored size: 769 Bytes

Contents

module Museum
  class Loupe < ::ApplicationRecord
    extend ::FriendlyId
    friendly_id :title, use: :slugged

    validates_presence_of :title

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

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

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

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

    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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
museum-0.5.8 app/models/museum/loupe.rb
museum-0.5.7 app/models/museum/loupe.rb
museum-0.5.6 app/models/museum/loupe.rb
museum-0.5.4 app/models/museum/loupe.rb
museum-0.5.3 app/models/museum/loupe.rb
museum-0.5.2 app/models/museum/loupe.rb
museum-0.5.1 app/models/museum/loupe.rb
museum-0.5.0 app/models/museum/loupe.rb