module LatoCore::Interface::General

This module contains a list of general functions used as helpers on the system.

Public Instance Methods

core__add_param_to_url(url, param_name, param_value) click to toggle source

This function add a new GET param to an url string.

# File lib/lato_core/interfaces/general.rb, line 30
def core__add_param_to_url(url, param_name, param_value)
  uri = URI(url)
  params = URI.decode_www_form(uri.query || "") << [param_name, param_value]
  uri.query = URI.encode_www_form(params)
  uri.to_s
end
core__get_string_inside_strings(string, marker1, marker2) click to toggle source

This function return the substring inside two strings.

# File lib/lato_core/interfaces/general.rb, line 19
def core__get_string_inside_strings(string, marker1, marker2)
  string[/#{Regexp.escape(marker1)}(.*?)#{Regexp.escape(marker2)}/m, 1]
end
core__paginate_array(array, per_page, page) click to toggle source

This function paginate an array and return the requested page.

# File lib/lato_core/interfaces/general.rb, line 24
def core__paginate_array(array, per_page, page)
  start = (page - 1) * per_page
  array[start, per_page]
end
core__read_yaml(file_path) click to toggle source

This function takes a path to a yaml file and return the hash with yaml data or nil if file not exist.

# File lib/lato_core/interfaces/general.rb, line 8
def core__read_yaml(file_path)
  # return nil if file not exist
  return unless File.exist?(file_path)
  config_file = File.read(file_path)
  # return yaml data
  return YAML.safe_load(config_file).with_indifferent_access
rescue
  nil
end