Module: Calligraphy::Utils

Included in:
FileResource
Defined in:
lib/calligraphy/utils.rb

Constant Summary collapse

TRUE_VALUES =
[true, 1, '1', 't', 'T', 'true', 'TRUE']
FALSE_VALUES =
[false, 0, '0', 'f', 'F', 'false', 'FALSE']

Instance Method Summary collapse

Instance Method Details

#extract_lock_token(if_header) ⇒ Object



34
35
36
# File 'lib/calligraphy/utils.rb', line 34

def extract_lock_token(if_header)
  if_header.scan(Calligraphy::LOCK_TOKEN_REGEX)&.flatten[0]
end

#is_false?(val) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/calligraphy/utils.rb', line 10

def is_false?(val)
  FALSE_VALUES.include? val
end

#is_true?(val) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/calligraphy/utils.rb', line 6

def is_true?(val)
  TRUE_VALUES.include? val
end

#join_paths(*paths) ⇒ Object



14
15
16
# File 'lib/calligraphy/utils.rb', line 14

def join_paths(*paths)
  paths.join '/'
end

#map_array_of_hashes(arr_hashes) ⇒ Object



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

def map_array_of_hashes(arr_hashes)
  [].tap do |output_array|
    arr_hashes.each do |hash|
      output_array.push hash.map { |k, v| v }
    end
  end
end

#obj_exists_and_is_not_type?(obj:, type:) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/calligraphy/utils.rb', line 22

def obj_exists_and_is_not_type?(obj:, type:)
  obj.nil? ? false : obj != type
end

#split_and_pop(path:, separator: '/') ⇒ Object



18
19
20
# File 'lib/calligraphy/utils.rb', line 18

def split_and_pop(path:, separator: '/')
  path.split(separator)[0..-2]
end