calvatar 0.1.0 → 0.1.2

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: 9d764df237673083fe0c74155ed30e6c3832aebc624aec86208b8bf99e27bf41
4
- data.tar.gz: a3d4b3740471069082e384e20d568f934c5e6ec993c8d8fd5340f251a3712b32
3
+ metadata.gz: 1ed16b97bc9e716297aa1166f2fc5f890b4b8d26b9924ff098f6feba59314741
4
+ data.tar.gz: 751f70838be604b7ac67f0c87136f52f7b58f6ad98a98fb908ded652066c8d9b
5
5
  SHA512:
6
- metadata.gz: d77b1c8e4ec13d15e9d7dedd01b524beb90b7b601fe257638399df94edd26c8a82aa5e83b99c60045eeb03214c760e5a49469afeae171552bd872bf3b3915e2f
7
- data.tar.gz: 815fbd86b10370c77a3b5025d294ee85068faec7fe0f9f9c2347699ab2a718c53c2b6da5d5ba0b0959815bd462d52fcb8e56b00d655688ad9e4f669b08bbe618
6
+ metadata.gz: c40556cd10b99a8e901bd982c8e830f7704ade22728e33fe318d52bff9f79728b29fe042f92bad8ca18f026fdf39d6e1de95575c883e45001d66a9c8fc57560d
7
+ data.tar.gz: 2b34f7417f58f22e86178af90b76a809cf5dd30bca806be01f6a3398c307ad6c3c8f01164ace3488df7a93b91c708f61c1cc9afa6d092f6472a2d0ef35654380
Binary file
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calvatar
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Calvatar
6
+
7
+ initializer 'calvatar.helper' do
8
+ ActionView::Base.include CalvatarHelper
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Calvatar
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/calvatar.rb CHANGED
@@ -1,37 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'calvatar/version'
4
+ require 'calvatar_helper'
4
5
 
5
6
  module Calvatar
6
7
  class Avatar
7
- COLORS = [
8
+ DEFAULT_COLORS = [
8
9
  '#FF5733', '#33FF57', '#3357FF', '#F1C40F', '#9B59B6',
9
10
  '#E67E22', '#1ABC9C', '#2ECC71', '#3498DB', '#34495E'
10
- ]
11
+ ].freeze
11
12
 
12
- def initialize(name)
13
+ DEFAULT_SIZE = 50
14
+
15
+ def initialize(name, colors: DEFAULT_COLORS, size: DEFAULT_SIZE)
13
16
  @initials = extract_initials(name)
14
- @color = COLORS.sample
17
+ @color = colors.sample
18
+ @size = size
15
19
  end
16
20
 
17
21
  def generate
18
22
  svg = <<~SVG
19
- <svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'>
20
- <rect width='100' height='100' fill='#{@color}'/>
21
- <text x='50%' y='50%' font-size='40' text-anchor='middle' fill='white' dy='.3em'>#{@initials}</text>
23
+ <svg xmlns='http://www.w3.org/2000/svg' width='#{@size}' height='#{@size}'>
24
+ <rect width='100%' height='100%' fill='#{@color}'/>
25
+ <text x='50%' y='50%' font-size='#{@size * 0.8}' text-anchor='middle' fill='white' dy='.3em'>#{@initials}</text>
22
26
  </svg>
23
27
  SVG
24
- svg.html_safe # Ensure the output is HTML safe for Rails
28
+ svg.html_safe
25
29
  end
26
30
 
27
- def self.generate_avatar(name)
28
- new(name).generate
31
+ def self.generate_avatar(name, colors: DEFAULT_COLORS, size: DEFAULT_SIZE)
32
+ new(name, colors: colors, size: size).generate
29
33
  end
30
34
 
31
35
  private
32
36
 
33
37
  def extract_initials(name)
34
- name.split.map(&:chr).join.upcase # Get initials from the name
38
+ name.split.map(&:chr).join.upcase
35
39
  end
36
40
  end
37
41
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CalvatarHelper
4
+ def calvatar_for(name, colors: Calvatar::Avatar::DEFAULT_COLORS, size: Calvatar::Avatar::DEFAULT_SIZE)
5
+ Calvatar::Avatar.generate_avatar(name, colors: colors, size: size)
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calvatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitória Calvi Meinerz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-19 00:00:00.000000000 Z
11
+ date: 2024-10-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -23,8 +23,11 @@ files:
23
23
  - LICENSE.txt
24
24
  - README.md
25
25
  - Rakefile
26
+ - calvatar-0.1.0.gem
26
27
  - lib/calvatar.rb
28
+ - lib/calvatar/engine.rb
27
29
  - lib/calvatar/version.rb
30
+ - lib/calvatar_helper.rb
28
31
  - sig/calvatar.rbs
29
32
  homepage: https://github.com/calvitoria/calvatar
30
33
  licenses: