Module: Ducalis::Utils

Defined in:
lib/ducalis/utils.rb

Class Method Summary collapse

Class Method Details

.octokitObject



9
10
11
12
13
14
15
16
# File 'lib/ducalis/utils.rb', line 9

def octokit
  @octokit ||= begin
    token = ENV.fetch('GITHUB_TOKEN') { raise MissingToken }
    Octokit::Client.new(access_token: token).tap do |client|
      client.auto_paginate = true
    end
  end
end

.silence_warningsObject



27
28
29
30
31
32
# File 'lib/ducalis/utils.rb', line 27

def silence_warnings
  original_verbose = $VERBOSE
  $VERBOSE = nil
  yield
  $VERBOSE = original_verbose
end

.similarity(string1, string2) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/ducalis/utils.rb', line 18

def similarity(string1, string2)
  longer = [string1.size, string2.size].max
  same = string1.each_char
                .zip(string2.each_char)
                .select { |char1, char2| char1 == char2 }
                .size
  1 - (longer - same) / string1.size.to_f
end