Class: AsciiArt

Inherits:
Object
  • Object
show all
Defined in:
lib/asciiart.rb,
lib/asciiart/version.rb

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_to_file) ⇒ AsciiArt

Returns a new instance of AsciiArt.



15
16
17
18
19
# File 'lib/asciiart.rb', line 15

def initialize(path_to_file)
  # open-uri open will fallback to IO open
  URI.open(path_to_file) { |file| @data = file.read }
  self
end

Instance Attribute Details

#image_chars=(value) ⇒ Object (writeonly)

Sets the attribute image_chars

Parameters:

  • value

    the value to set the attribute image_chars to.



13
14
15
# File 'lib/asciiart.rb', line 13

def image_chars=(value)
  @image_chars = value
end

Instance Method Details

#to_ascii_art(options = {}) ⇒ Object



21
22
23
24
25
26
# File 'lib/asciiart.rb', line 21

def to_ascii_art(options = {})
  options = { width: 100, color: false, format: "text" }.merge(options)
  img = Magick::Image.from_blob(@data).first
  renderer =  (options[:format] == "text" ? AsciiRenderer::Text.new(img) : AsciiRenderer::Html.new(img))
  renderer.to_ascii_art(options)
end