class Arduino::Library::Database

This class represents a single entry into the library-index.json file, in other words — a `library.properties` file.

Attributes

db_list[RW]
local_file[RW]

Public Class Methods

new(file_or_url) click to toggle source
# File lib/arduino/library/database.rb, line 27
def initialize(file_or_url)
  self.local_file = read_file_or_url(file_or_url)
  load_json
end

Public Instance Methods

Protected Instance Methods

entry_matches?(entry, opts) click to toggle source
# File lib/arduino/library/database.rb, line 50
def entry_matches?(entry, opts)
  matches = true
  opts.each_pair do |attr, check|
    value   = entry.send(attr)
    matches &= case check
                 when String
                   value == check
                 when Regexp
                   value =~ check
                 when Array
                   value = value.split(',') unless value.is_a?(Array)
                   value.eql?(check) || value.include?(check) || value.first == '*'
                 when Proc
                   check.call(value)
                 else
                   raise ::OptionParser::InvalidArgument, "Class #{check.class.name} is unsupported for value checks"
               end
    break unless matches
  end
end

Private Instance Methods

load_json() click to toggle source
# File lib/arduino/library/database.rb, line 73
def load_json
  hash         = JSON.load(local_file.read)
  self.db_list = hash['libraries'].map { |lib| Model.from_hash(lib) }
end