Class: VirtualNameCard::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/virtual_name_card/generator.rb

Constant Summary collapse

GENERATED_FILE_PATH =
File.expand_path("../../generated_file.png", __dir__)

Class Method Summary collapse

Class Method Details

.build(name_kanji:, name_romaji:, role: nil, email: nil, twitter_account: nil, url: nil) ⇒ VirtualNameCard::Image

Parameters:

  • name_kanji (String)
  • name_romaji (String)
  • role (String, nil) (defaults to: nil)
  • email (String, nil) (defaults to: nil)
  • twitter_account (String, nil) (defaults to: nil)
  • url (String, nil) (defaults to: nil)

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/virtual_name_card/generator.rb', line 17

def build(name_kanji:, name_romaji:, role: nil, email: nil, twitter_account: nil, url: nil)
  base_image_path =
    if 
      File.expand_path("../../base_images/with_twitter.jpg", __dir__)
    else
      File.expand_path("../../base_images/without_twitter.jpg", __dir__)
    end

  image = MiniMagick::Image.open(base_image_path)

  name_kanji_combine(image: image, text: name_kanji)
  name_romaji_combine(image: image, text: name_romaji)

  if role
    role_combine(image: image, text: role)
  end

  if email
    email_combine(image: image, text: email)
  end

  if 
    (image: image, text: )
  end

  if url
    image = url_combine(image: image, url: url)
  end

  VirtualNameCard::Image.new(mini_magick_image: image)
end

.generate(name_kanji:, name_romaji:, role: nil, email: nil, twitter_account: nil, url: nil) ⇒ Object

Parameters:

  • name_kanji (String)
  • name_romaji (String)
  • role (String, nil) (defaults to: nil)
  • email (String, nil) (defaults to: nil)
  • twitter_account (String, nil) (defaults to: nil)
  • url (String, nil) (defaults to: nil)


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/virtual_name_card/generator.rb', line 55

def generate(name_kanji:, name_romaji:, role: nil, email: nil, twitter_account: nil, url: nil)
  image = build(
    name_kanji: name_kanji,
    name_romaji: name_romaji,
    role: role,
    email: email,
    twitter_account: ,
    url: url,
  )
  image.mini_magick_image.write GENERATED_FILE_PATH
end