mp-utils 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f99dcd4e1535b4b1777fd10c0659634b4687ac24c47ba7a0c2c967f77beb9a3
4
- data.tar.gz: c2af79547fa099dba14ffdadb49bcf5892a30fab76f02f98aff3aa048a256336
3
+ metadata.gz: 472fb772fc669be45aee52e5f931823934e59cb5f36974536dbfea782024ac9d
4
+ data.tar.gz: 9c5079304a471c97261ec621457575b1b79c9454a8a60f7d19ee9b0a51a7c777
5
5
  SHA512:
6
- metadata.gz: 0c35d7a60dcf86f0c908c2b9f2380ae4bb41ff5e73d1e42315f919646c77f1471b43ecf679aaece84182922cef639c21f75ce88320f60a94a70ce126b2ddf540
7
- data.tar.gz: ff1a0de07a11334ac444eaf9328c482d45b8b7271dd13e9df622fc4528753cf5c0d1a0e556eaab50ee458e24118d3c6ae1a3bb8bf76ab97318c4effb9a4287f4
6
+ metadata.gz: 79864c2f162bb4d136ae0762d4196c868e0ce4136a31bb873ce79289478734f442acfc18e882d942b53b15e26c570a8b4d18c144f88d1ceae4573c01121583d8
7
+ data.tar.gz: cd1ed6a8fdb3c724d1953c0df5107468936b5a4800b537097ca32d3f134123c93f39c45ee327a347037e6246fe23600030128fe12f7371034d11bca9fb347204
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # The Resources module manages and provides access to file system paths used by a script or application.
4
+ #
4
5
  # It facilitates the definition and retrieval of a default library path, alongside a customizable path
5
- # that can be set at runtime either programmatically using the {define} method or through the environment
6
- # variable "SCRIPT_CUSTOM_RESOURCES". This flexibility allows applications to dynamically access resources
7
- # stored in various locations, depending on execution environment or user-defined settings.
6
+ # that can be set at runtime either programmatically using the {define} method or through the
7
+ # environment variable "SCRIPT_CUSTOM_RESOURCES".
8
+ #
9
+ # This flexibility allows applications to dynamically access resources stored in various locations,
10
+ # depending on execution environment or user-defined settings.
8
11
  module Resources
9
12
  # Retrieves the path to the directory containing this module, which serves as the default library path.
10
13
  #
@@ -4,11 +4,81 @@ require_relative 'constants'
4
4
  require_relative 'ansi'
5
5
 
6
6
  # The ANSIStyleManager class is responsible for managing and applying ANSI styles to a given string.
7
- # It can replace tokens in the string with corresponding ANSI codes for colors and effects.
8
7
  #
9
- # @example
10
- # manager = ANSIStyleManager.new("Hello <color:red>World</color>")
11
- # puts manager.to_s # => "Hello \e[31mWorld\e[39m"
8
+ # It can replace tokens in the string with corresponding ANSI codes for colors, backgrounds and effects.
9
+ #
10
+ # ## Effects
11
+ # Effects can be used by adding `<effect:effect_name>` at the beginning and `</effect>` at the end of
12
+ # the sequence of characters to which you want the effect to be applied.
13
+ #
14
+ # Example:
15
+ # ```ruby
16
+ # manager = ANSIStyleManager.new('The text <effect:bold>Potato</effect> will be bold.')
17
+ # puts manager
18
+ # ```
19
+ # Output:
20
+ #
21
+ # ![bold output](./.resources/images/bold_effect_example.png)
22
+ #
23
+ # Below is the table with all available effects:
24
+ #
25
+ # | Effect Name | Description |
26
+ # |---------------|----------------------------|
27
+ # | bold | set bold mode. |
28
+ # | faint | set dim/faint mode. |
29
+ # | italic | set italic mode. |
30
+ # | underline | set underline mode. |
31
+ # | blinking | set blinking mode. |
32
+ # | inverse | set inverse/reverse mode. |
33
+ # | hidden | set hidden/invisible mode. |
34
+ # | strike | set strikethrough mode. |
35
+ # | plain | set double underline mode. |
36
+ #
37
+ # > **Note:** Some terminals may not support some of the effects listed above.
38
+ #
39
+ # ## Colors
40
+ # The ANSIStyleManager supports 3 types of coloring: Named Colors, RGB Colors, or 256 Colors.
41
+ #
42
+ # The foreground color can be changed by adding `<color:color_type>` at the beginning and `</color>`
43
+ # at the end of the character sequence you want to color.
44
+ #
45
+ # Example:
46
+ # ```ruby
47
+ # text = 'A <color:green>colorful <color:red>world <color:yellow>is <color:blue>much '
48
+ # text += '</color>more </color>beautiful</color>!</color> ;)'
49
+ # manager = ANSIStyleManager.new(text)
50
+ # puts manager
51
+ # ```
52
+ # Output:
53
+ #
54
+ # ![colored output](./.resources/images/foreground_colored_example.png)
55
+ #
56
+ # It is also possible to set the background color of a text.
57
+ #
58
+ # The background color can be changed by adding `<color:color_type:color_type>` at the
59
+ # beginning and `</color>` at the end of the character sequence you want to color.
60
+ #
61
+ # Example:
62
+ # ```ruby
63
+ # text = 'A <color:green:white>colorful <color:196>world <color:yellow:111>is <color:blue:255;255;255>much '
64
+ # text += '</color>more </color>beautiful</color>!</color> ;)'
65
+ # manager = ANSIStyleManager.new(text)
66
+ # puts manager
67
+ # ```
68
+ #
69
+ # Output:
70
+ #
71
+ # ![colored output](./.resources/images/background_colored_exemple.png)
72
+ #
73
+ # Below is the table with all available color type patterns:
74
+ #
75
+ # |Color Type |Pattern |Description |
76
+ # |-------------|--------|---------------------------------------------------------------------------------------------|
77
+ # |Reset colors |reset |Resets to the terminal's default color. |
78
+ # |256 Colors |number |Accepts numbers between 0 and 255. |
79
+ # |RGB Colors |R;G;B |R, G, and B accept values between 0 and 255. |
80
+ # |Named Colors |name |Accepts the following color names: black, red, green, yellow, blue, magenta, cyan and white. |
81
+ #
12
82
  class ANSIStyleManager
13
83
  # @return [String] the string to which ANSI styles will be applied.
14
84
  attr_reader :string
data/lib/utils/key.rb CHANGED
@@ -45,10 +45,7 @@ class Key
45
45
  def to_regexp
46
46
  /#{Regexp.escape(to_s)}/
47
47
  end
48
- end
49
48
 
50
- # Static Methods
51
- class Key
52
49
  # Finds and returns all Key instances within the given string.
53
50
  #
54
51
  # @param value [#to_s] the string to search for keys.
data/lib/utils/message.rb CHANGED
@@ -4,11 +4,15 @@ require_relative File.join('..', 'resources', 'path_helper')
4
4
  require_relative 'key'
5
5
 
6
6
  # The Message class represents a mechanism for dynamically handling and formatting messages.
7
+ #
7
8
  # It supports the substitution of placeholders within a message template with actual data.
8
- # The class leverages file-based message templates, allowing for easy localization or customization
9
- # of messages. It integrates seamlessly with the Resources module to access these templates from
10
- # a customizable path set via the "SCRIPT_CUSTOM_RESOURCES" environment variable or from a default
11
- # library path.
9
+ #
10
+ # The class leverages file-based message templates, allowing for easy localization or
11
+ # customization of messages.
12
+ #
13
+ # It integrates seamlessly with the Resources module to access these templates from
14
+ # a customizable path set via the "SCRIPT_CUSTOM_RESOURCES" environment variable or
15
+ # from a default library path.
12
16
  #
13
17
  # @example Creating a new Message instance and formatting it
14
18
  # # Assuming "hellow_world" is a file that says "Hello, world!"
@@ -46,10 +50,7 @@ class Message
46
50
  new_message = replace_message_keys(String.new(@message))
47
51
  replace_all_to_replace_elements(new_message)
48
52
  end
49
- end
50
53
 
51
- # Private Methods
52
- class Message
53
54
  private
54
55
 
55
56
  # Determines the custom path for message files, if set through the "SCRIPT_CUSTOM_RESOURCES" environment variable.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mp-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcio F Paludo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-30 00:00:00.000000000 Z
11
+ date: 2024-07-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Helpers to facilitate scripts Writing.