Fledex.Color.Names.LoadUtils (fledex v0.7.0)
View SourceSome utility functions that can help when loading color names from a CSV file
Summary
Functions
Converts an asci string representing a byte into that byte
Converts an asci string with an integer into an integer.
Converts a hex string (potentially with a # sign) into an integer
This function is used by the Generator, but is not intended to be used otherwise it is for loading the CSV files in a decently generic way.
Converts a string (can be even unicode) into an asci atom
Functions
@spec a2b(String.t()) :: 0..255
Converts an asci string representing a byte into that byte
The value is interpreted as a value between 0 and 255 except in the following special cases:
%: If the string contains a trailing percent sign, thenthe value is interpreted as a percent and stretched onto a byte°: If the string contains a trailing degree sign, thenthe value is interpreted degree between 0 and 359 and mapped to a byte
Converts an asci string with an integer into an integer.
Any non-digit charaters will be removed before the conversion
Converts a hex string (potentially with a # sign) into an integer
@spec load_color_file( String.t(), ([String.t() | integer()] -> Fledex.Color.Names.Types.color_struct_t()), keyword() ) :: %{required(atom()) => Fledex.Color.Names.Types.color_struct_t()}
This function is used by the Generator, but is not intended to be used otherwise it is for loading the CSV files in a decently generic way.
You have to specify the following parameters:
filename(mandatory): The color file you want to processconverter(mandatory): This is a function needs to do the conversion from the different parts of a line into acolor_struct_tstructure.
You can in addition specify the following options:
name_pattern(default:~r/^.*$/i): which names you want to actually want to load. Anydescriptive_namethat does not match this pattern will be dropped. You can for example only load the rows starting with ana.drop(default: 1): how many header rows should be dropped. This allows to remove the header in a CSV file.splitter_opts(default: []): The ops that will be used when splitting a line into the different parts. On one side it should contain the:separator(defaults to,as used in a proper CSV) and anysplit_optsas used byString.split/3.module(default: :unknown): The name of the module that created the color map. This will automatically be added to thecolor_struct_tstructure.comment_pattern(default:~r/^s*#.*$/): A pattern that will filter out any lines defined as comment lines (similar to code where the line might start with a#).
Converts a string (can be even unicode) into an asci atom
It performs the following steps:
- normalizes the string (NFD form)
- replaces any non-alpha-numeric characters with underscores (except at the start and end)
- downcases it
- converts it to an atom