Class: ArTTY::Generator
- Inherits:
-
Object
- Object
- ArTTY::Generator
- Defined in:
- lib/arTTY/generator.rb
Instance Method Summary collapse
- #generate(image, name = nil) ⇒ Object
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/arTTY/generator.rb', line 128 def initialize if (ScoobyDoo.where_are_you("convert").nil?) raise ArTTY::Error::ImageMagickNotFound.new end @keys = Array.new key = "!" while key != "~" do @keys.push(key.clone) case key when "!" key = "#" when "9" key = ":" when "Z" key = "[" when "[" key = "]" when "_" key = "a" when "z" key = "{" else key.next! end end @keys.push("~") end |
Instance Method Details
#generate(image, name = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/arTTY/generator.rb', line 4 def generate(image, name = nil) file = Pathname.new(image). pixels = nil if (!file.exist?) raise ArTTY::Error::ImageNotFound.new(file.to_s) end file.to_s.match(%r{([^/]+?)(_(\d+)x(\d+))?\.}) do |m| name = m[1] if (name.nil? || name.empty?) width = m[3].nil? ? nil : m[3].to_i height = m[4].nil? ? nil : m[4].to_i pixels = get_pixel_info(file, width, height) end raise ArTTY::Error::NoPixelDataFound.new if (pixels.empty?) legend = generate_color_map(pixels) return generate_json(name, pixels, legend) end |